增加采购汇总 查询的 明细

This commit is contained in:
杰 朱
2021-05-25 11:59:26 +08:00
parent 0929b0e37d
commit 9f8d2a177a
5 changed files with 329 additions and 42 deletions

View File

@@ -200,10 +200,10 @@ namespace NX.ERP.U8.Purchase
}
}
public IEnumerable<object> Purchasesum()
public IEnumerable<object> Purchasesum(NX.ERP.Model.Request.PurchasesumRequest info)
{
string sql = $@"
DECLARE @RdRecord table(
DECLARE @RdRecord table(
cPsn_Num nvarchar(30),
cpersonname nvarchar(30),
puappnumall int,
@@ -318,7 +318,7 @@ namespace NX.ERP.U8.Purchase
mom_morder mor WITH (NOLOCK) ON ma.MoDId= mor.MoDId
WHERE md.Status <> 4 AND ma.Qty - ISNULL(ma.IssQty, 0) > 0 and
convert(varchar,mor.DueDate,112) < convert(varchar,dateadd(day,-day(getdate()),dateadd(month,3,getdate())),112)
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
@@ -337,8 +337,8 @@ namespace NX.ERP.U8.Purchase
update a set a.mommouth02=b.puappnumall From @RdRecord a left join @RdRecord4 b on a.cpersonname =b.cpersonname
update a set a.mommouth02= a.puappnumall +b.puappnumall From @RdRecord a left join (
select '其他' as cpersonname ,sum(puappnumall) as puappnumall from @RdRecord4 where cpersonname not in (select cpersonname From @RdRecord) )b on a.cpersonname =b.cpersonname
update a set a.mommouth02= a.mommouth02 +b.mommouth02 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='其他'
@@ -355,7 +355,7 @@ namespace NX.ERP.U8.Purchase
mom_morder mor WITH (NOLOCK) ON ma.MoDId= mor.MoDId
WHERE md.Status <> 4 AND ma.Qty - ISNULL(ma.IssQty, 0) > 0 and
convert(varchar,mor.DueDate,112) < convert(varchar,dateadd(day,-day(getdate()),dateadd(month,5,getdate())),112)
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
@@ -376,8 +376,8 @@ namespace NX.ERP.U8.Purchase
update a set a.mommouth04=b.puappnumall From @RdRecord a left join @RdRecord5 b on a.cpersonname =b.cpersonname
update a set a.mommouth04= a.puappnumall +b.puappnumall From @RdRecord a left join (
select '其他' as cpersonname ,sum(puappnumall) as puappnumall from @RdRecord5 where cpersonname not in (select cpersonname From @RdRecord) )b on a.cpersonname =b.cpersonname
update a set a.mommouth04= a.mommouth04 +b.mommouth04 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='其他'
@@ -385,14 +385,13 @@ namespace NX.ERP.U8.Purchase
";
using (var conn = new System.Data.SqlClient.SqlConnection("Data Source =127.0.0.1;Initial Catalog =UFDATA_002_2019;User Id = sa;Password =123;"))
using (var conn = NX.ERP.U8.U8LoginContext.Instance.Connection)
{
return conn.Query<object>(sql, new { });
return conn.Query<object>(sql, new { info.BeginDate, info.EndDate, info.BeginDate2, info.EndDate2 });
}
}
@@ -421,7 +420,7 @@ namespace NX.ERP.U8.Purchase
}
if (info.InvCodes != null)
{
where.Add(" puu.cInvCode = @InvCodes");
where.Add(" puu.cInvCode in @InvCodes");
}
if (info.cday > 0)
{
@@ -435,11 +434,59 @@ namespace NX.ERP.U8.Purchase
}
using (var conn = new System.Data.SqlClient.SqlConnection("Data Source =127.0.0.1;Initial Catalog =UFDATA_002_2019;User Id = sa;Password =123;"))
using (var conn = NX.ERP.U8.U8LoginContext.Instance.Connection)
{
return conn.Query<object>(sql, new { info.cpersonname, info.InvCodes, info.cday });
}
}
public IEnumerable<object> Purchasesummom(NX.ERP.Model.Request.PurchasesumRequest info)
{
string sql = $@"
select *from (
select a.*,isnull(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 Inventory inv WITH (NOLOCK) on a.CINVCODE=inv.cInvCode )pumo
";
List<string> where = new List<string>();
if (!string.IsNullOrEmpty(info.cpersonname))
{
where.Add(" pumo.cpersonname = @cpersonname");
}
if (info.InvCodes != null)
{
where.Add(" pumo.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<object>(sql, new { info.cpersonname, info.InvCodes, info.cday, info.BeginDate, info.EndDate });
}
}
}
}