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
{
///
///
///
///
///
///
public IEnumerable 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 where = new List();
if (!string.IsNullOrEmpty(info1.cMaker))
{
where.Add(" mmm.cpersonname like @cMaker");
}
if (!string.IsNullOrEmpty(info1.vendor))
{
where.Add(" mmm.cvenabbname like @vendor ");
}
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)
{
return conn.Query(sql, new { cinvcode = info1.InvCodes, info1.cMaker, info1.vendor, cInvStd = $"%{info1.InvStd}%", info1.PoCodes, info1.AppCodes, info1.BeginDate, info1.EndDate, info1.BeginDate2, info1.EndDate2 });
}
}
public IEnumerable Purchasesum(NX.ERP.Model.Request.PurchasesumRequest info)
{
string sql = $@"
DECLARE @RdRecord table(
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
select cPsn_Num, cPsn_Name,0,0,0,0 from hr_v_HR31_show WITH (nolock) where cDepCode ='52' and rEmployState ='在职' and cPsn_Name <>'朱华英'
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)
GROUP BY iAppIds) rds ON isnull(ommds.autoid,'') = isnull(rds.iAppIds,'')
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
ommds.fquantity - ISNULL(rds.qty, 0) > 0) OM
GROUP BY cInvCode
) as tbl1
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
)
as tbl on tbl1.cinvcode=tbl.cInvCode
) q group by cPsn_Num
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
update a set a.puappnumall=isnull(b.puappnumall,0) From @RdRecord a left join
(select cpersonname,sum(puappnumall) as puappnumall from @RdRecord2 group by cpersonname ) b on a.cpersonname =b.cpersonname
update a set a.puappnumall= isnull(a.puappnumall,0) +isnull(b.puappnumall,0) From @RdRecord a left join (
select '其他' as cpersonname ,sum(puappnumall) as puappnumall from @RdRecord2 where cpersonname not in (select cpersonname From @RdRecord) )b on a.cpersonname =b.cpersonname
where a.cpersonname='其他'
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)
GROUP BY iAppIds) rds ON isnull(ommds.autoid,'') = isnull(rds.iAppIds,'')
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
ommds.fquantity - ISNULL(rds.qty, 0) > 0) OM
GROUP BY cInvCode
) as tbl1
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
)
as tbl on tbl1.cinvcode=tbl.cInvCode
) q group by cPsn_Num
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
update a set a.puappnum03=isnull(b.puappnumall,0) From @RdRecord a left join
(select cpersonname,sum(puappnumall) as puappnumall from @RdRecord3 group by cpersonname) b on a.cpersonname =b.cpersonname
update a set a.puappnum03= isnull(a.puappnum03,0) +isnull(b.puappnumall,0) From @RdRecord a left join (
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
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) OM
GROUP BY cInvCode
) as tbl1
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
)
as tbl on tbl1.cinvcode=tbl.cInvCode )
q group by cPsn_Num
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
update a set a.mommouth02=isnull(b.puappnumall,0) From @RdRecord a left join
(select cpersonname,sum(puappnumall) as puappnumall from @RdRecord4 group by cpersonname
) b on a.cpersonname =b.cpersonname
update a set a.mommouth02= isnull(a.mommouth02,0) +isnull(b.mommouth02,0) From @RdRecord a left join (
select '其他' as cpersonname ,sum(puappnumall) as mommouth02 from @RdRecord4 where cpersonname not in (select cpersonname From @RdRecord) )b on a.cpersonname =b.cpersonname
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
mor.DueDate between @beginDate2 and @endDate2
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
(
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
)
as tbl on tbl1.cinvcode=tbl.cInvCode )
q group by cPsn_Num
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
update a set a.mommouth04=isnull(b.puappnumall,0) From @RdRecord a left join (
select cpersonname,sum(puappnumall) as puappnumall from @RdRecord5 group by cpersonname) b on a.cpersonname =b.cpersonname
update a set a.mommouth04= isnull(a.mommouth04,0) +isnull(b.mommouth04,0) From @RdRecord a left join (
select '其他' as cpersonname ,sum(puappnumall) as mommouth04 from @RdRecord5 where cpersonname not in (select cpersonname From @RdRecord) )b on a.cpersonname =b.cpersonname
where a.cpersonname='其他'
delete from @RdRecord where cpersonname in (select quit from CGBB2021_0001_E001)
select *from @RdRecord
";
using (var conn = NX.ERP.U8.U8LoginContext.Instance.Connection)
{
return conn.Query(sql, new { info.BeginDate, info.EndDate, info.BeginDate2, info.EndDate2 });
}
}
public IEnumerable Purchasesumpuapp(NX.ERP.Model.Request.PurchasesumRequest info)
{
string sql = $@"
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
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)
GROUP BY iAppIds) rds ON isnull(ommds.autoid,'') = isnull(rds.iAppIds,'')
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 ommds.cInvCode =f.cInvCode
left join CGBB2021_0001_E001 k WITH (NOLOCK) on f.cMaker =k.quit
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
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
";
List where = new List();
if (!string.IsNullOrEmpty(info.cpersonname))
{
where.Add(" puu.cMaker = @cpersonname");
}
if (info.InvCodes != null)
{
where.Add(" puu.cInvCode in @InvCodes");
}
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;
}
using (var conn = NX.ERP.U8.U8LoginContext.Instance.Connection)
{
return conn.Query(sql, new { info.cpersonname, info.InvCodes, info.cday });
}
}
public IEnumerable Purchasesummom(NX.ERP.Model.Request.PurchasesumRequest info)
{
string sql = $@"
IF EXISTS (SELECT NAME FROM tempdb..SYSOBJECTS WHERE NAME ='tablemom20210625' AND Xtype='U') DROP Table tempdb..tablemom20210625
create table tempdb..tablemom20210625 (
CINVCODE nvarchar(200),
RQTY int,
iqty int,
iQuantity int,
bull int,
cpersonname nvarchar(200),
cInvName nvarchar(200),
cInvStd nvarchar(500)
)
insert into tempdb..tablemom20210625
select *from (
select a.*,isnull(isnull(k.receive ,f.cMaker),'其他') as cpersonname ,inv.cInvName,inv.cInvStd from (
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
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
left join CGBB2021_0001_E001 k WITH (NOLOCK) on f.cMaker =k.quit
left join Inventory inv WITH (NOLOCK) on a.CINVCODE=inv.cInvCode )pumo
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))
select *From tempdb..tablemom20210625
";
List where = new List();
if (!string.IsNullOrEmpty(info.cpersonname))
{
where.Add(" cpersonname = @cpersonname");
}
if (info.InvCodes != null)
{
where.Add(" cInvCode = @InvCodes");
}
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(sql, new { info.cpersonname, info.InvCodes, info.cday, info.BeginDate, info.EndDate });
}
}
public NX.ERP.Model.PmcWwInvlRes Purchasesuww()
{
var PmcWwInvlRes = new NX.ERP.Model.PmcWwInvlRes();
using (var conn = U8LoginContext.Instance.Connection)
{
var sql = @" SELECT [TaskItemID]
,[CenterCode]
,[CenterName]
,[WorkCode]
,[WorkName],
[code]
, b.cInvName [Name]
,b.cInvStd [Standard]
,[SrcBlockCode]
,[SrcBlockName]
,[DstBlockCode]
,[DstBlockName]
,convert( decimal(20,2),RecQua) as [RecQua]
,[SupplierName]
,[Price]
,[RecTime]
FROM [10.0.0.230].[wxnx2021].[dbo].[WX_WWsend] a
left join Inventory b WITH (NOLOCK) on isnull(a.code,'')=isnull(b.cInvCode ,'')
";
PmcWwInvlRes.wfdetails=conn.Query< NX.ERP.Model.wfdetail> (sql,"" );
var sql2 = @" SELECT [SheetDate]
,[SheetID]
,[code]
,[Name]
,[Standard]
,[Qua]
,isnull(ReceivedQua,0) as ReceivedQua
, ([Qua]- isnull(ReceivedQua,0)) as diff
FROM [10.0.0.230].[wxnx2021].[dbo].[WX_WWrec]
";
PmcWwInvlRes.wsdetails = conn.Query(sql2, "");
PmcWwInvlRes.wfjl = PmcWwInvlRes.wfdetails.Count();
PmcWwInvlRes.wsjl = PmcWwInvlRes.wsdetails.Count();
}
return PmcWwInvlRes;
}
}
}