2021-04-29 13:55:18 +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.Pmc
|
|
|
|
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
public class PmcQuery
|
|
|
|
|
|
{
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
///
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="strWhere"></param>
|
|
|
|
|
|
/// <param name="param"></param>
|
|
|
|
|
|
/// <returns></returns>
|
2021-04-29 14:37:23 +08:00
|
|
|
|
public IEnumerable<NX.ERP.Model.PmcInventoryallRes> GetPmcInventoryallRes(NX.ERP.Model.Request.Inventoryall info)
|
2021-04-29 13:55:18 +08:00
|
|
|
|
{
|
|
|
|
|
|
string sql = $@"
|
|
|
|
|
|
SELECT c.cInvCode invcode1,
|
|
|
|
|
|
c.cInvName cinvname1, c.cInvStd cinvstd1,LL.cComUnitName, CASE WHEN c.bPurchase = 1 AND
|
|
|
|
|
|
c.bProxyForeign = 1 THEN '委外' WHEN c.bPurchase = 1 THEN '外购' WHEN c.bself = 1 THEN '自制' ELSE '其它' END AS
|
|
|
|
|
|
std, isnull(mas.wqty,0) wqty, ISNULL(cs.qty, 0) cqty,ISNULL(misss.issqty, 0) issqty , ISNULL(ds.qty, 0) dqty,isnull(prd.Rqty, 0) rqty,
|
|
|
|
|
|
ISNULL(OMM.RQTY1, 0) AS rqty1, ISNULL(pu_App.RQTY3, 0) AS rqty3,ISNULL(momq.momqty, 0) AS momqty, ISNULL(MX.MQTY, 0) MQTY, isnull(mas.wqty,0) - isnull(cs.qty, 0) - ISNULL(prd.Rqty, 0)
|
|
|
|
|
|
- ISNULL(omm.RQTY1, 0) - ISNULL(MX.MQTY, 0) AS q
|
|
|
|
|
|
|
|
|
|
|
|
FROM Inventory c LEFT JOIN
|
|
|
|
|
|
(SELECT ma.invcode, SUM(isnull(ma.qty, 0) - isnull(issqty, 0)) wqty
|
|
|
|
|
|
FROM mom_moallocate ma INNER JOIN
|
|
|
|
|
|
mom_orderdetail md ON ma.MoDId = md.MoDId
|
|
|
|
|
|
WHERE md.Status <> 4 AND ma.Qty - ISNULL(ma.IssQty, 0) > 0
|
|
|
|
|
|
GROUP BY ma.InvCode) mas ON c.cInvCode = mas.InvCode LEFT JOIN
|
|
|
|
|
|
(SELECT ma.invcode, SUM( isnull(issqty, 0)) issqty
|
|
|
|
|
|
FROM mom_moallocate ma INNER JOIN
|
|
|
|
|
|
mom_orderdetail md ON ma.MoDId = md.MoDId
|
|
|
|
|
|
WHERE md.Status <> 4
|
|
|
|
|
|
GROUP BY ma.InvCode) misss ON c.cInvCode = misss.InvCode LEFT JOIN
|
|
|
|
|
|
|
|
|
|
|
|
(SELECT cinvcode, SUM(iquantity) qty
|
|
|
|
|
|
FROM currentstock
|
|
|
|
|
|
GROUP BY cInvCode) cs ON c.cInvCode = cs.cInvCode
|
|
|
|
|
|
LEFT JOIN
|
|
|
|
|
|
(SELECT cinvcode, SUM(iquantity) qty
|
|
|
|
|
|
FROM InvPositionSum where cPosCode not in ('00701','00801','09001')
|
|
|
|
|
|
GROUP BY cInvCode) ds ON c.cInvCode = ds.cInvCode
|
|
|
|
|
|
LEFT JOIN
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
(SELECT MD.INVCODE, SUM(MD.QTY - ISNULL(MD.QUALIFIEDINQTY, 0)) AS MQTY
|
|
|
|
|
|
FROM mom_orderdetail MD
|
|
|
|
|
|
GROUP BY MD.INVCODE) MX ON c.cInvCode = MX.InvCode LEFT JOIN
|
|
|
|
|
|
(SELECT cinvcode, SUM(rqty) AS rqty
|
|
|
|
|
|
FROM (SELECT PDS.cInvCode, PDS.iQuantity - ISNULL(rds.qty, 0) AS Rqty
|
|
|
|
|
|
FROM PO_Pomain PM WITH (NOLOCK) INNER JOIN
|
|
|
|
|
|
PO_Podetails PDS WITH (NOLOCK) ON PM.POID = PDS.POID LEFT JOIN
|
|
|
|
|
|
(SELECT IPOSID, SUM(IQUANTITY) AS QTY
|
|
|
|
|
|
FROM rdrecords01 rds WITH (NOLOCK) INNER JOIN
|
|
|
|
|
|
RdRecord01 rd WITH (nolock) ON rds.ID = rd.ID
|
|
|
|
|
|
WHERE CBUSTYPE = '普通采购'
|
|
|
|
|
|
GROUP BY IPOSID) RDS ON PDS.ID = RDS.iPOsID
|
|
|
|
|
|
WHERE ISNULL(PM.CCLOSER, N'') = N'' AND ISNULL(PDS.CBCLOSER, N'') = N'' AND
|
|
|
|
|
|
pds.iQuantity - ISNULL(rds.qty, 0) > 0) x
|
|
|
|
|
|
GROUP BY cInvCode) prd ON c.cInvCode = prd.cInvCode LEFT JOIN
|
|
|
|
|
|
(SELECT CINVCODE, SUM(RQTY) AS RQTY1
|
|
|
|
|
|
FROM (SELECT ommds.cInvCode, ommds.iQuantity - ISNULL(rds.qty, 0) AS rqty
|
|
|
|
|
|
FROM OM_MOMain omm WITH (nolock) INNER JOIN
|
|
|
|
|
|
OM_MODetails ommds WITH (nolock) ON omm.MOID = ommds.MOID LEFT JOIN
|
|
|
|
|
|
(SELECT iomodid, sum(iquantity) AS qty
|
|
|
|
|
|
FROM rdrecords01 WITH (nolock)
|
|
|
|
|
|
GROUP BY iOMoDID) rds ON ommds.MODetailsID = rds.iOMoDID
|
|
|
|
|
|
WHERE ISNULL(OMM.cCloser, N'') = N'' AND ISNULL(ommds.cbCloser, N'') = N'' AND
|
|
|
|
|
|
ommds.iQuantity - ISNULL(rds.qty, 0) > 0) OM
|
|
|
|
|
|
GROUP BY cInvCode) OMM ON c.cInvCode = OMM.CINVCODE LEFT JOIN
|
|
|
|
|
|
(SELECT CINVCODE, SUM(RQTY) AS RQTY3
|
|
|
|
|
|
FROM (SELECT ommds.cInvCode, ommds.fquantity - ISNULL(rds.qty, 0) 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 ommds.autoid = rds.iAppIds
|
|
|
|
|
|
WHERE ISNULL(OMM.cCloser, N'') = N'' AND ISNULL(ommds.cbCloser, N'') = N'' AND
|
|
|
|
|
|
ommds.fquantity - ISNULL(rds.qty, 0) > 0) OM
|
|
|
|
|
|
GROUP BY cInvCode) pu_App ON c.cInvCode = pu_App.CINVCODE LEFT JOIN
|
|
|
|
|
|
(select InvCode,sum(qty) as momqty from mom_orderdetail where Status=3 group by InvCode) momq on c.cInvCode = momq.InvCode
|
|
|
|
|
|
|
|
|
|
|
|
left join ComputationUnit LL WITH (nolock) on c.cComUnitCode=LL.cComunitCode
|
|
|
|
|
|
";
|
|
|
|
|
|
|
|
|
|
|
|
List<string> where = new List<string>();
|
|
|
|
|
|
|
2021-04-30 11:51:19 +08:00
|
|
|
|
if (info.InvCodes != null)
|
2021-04-29 13:55:18 +08:00
|
|
|
|
{
|
|
|
|
|
|
where.Add(" c.cinvcode in @cinvcode");
|
|
|
|
|
|
}
|
2021-04-30 11:51:19 +08:00
|
|
|
|
if (!string.IsNullOrEmpty(info.InvStd))
|
2021-04-29 13:55:18 +08:00
|
|
|
|
{
|
|
|
|
|
|
where.Add(" c.cInvStd like @cInvStd ");
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
var aa = string.Join(" and ", where.ToArray());
|
|
|
|
|
|
|
|
|
|
|
|
if (!string.IsNullOrEmpty(aa))
|
|
|
|
|
|
{
|
|
|
|
|
|
sql += "where " + aa;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2021-04-29 14:37:23 +08:00
|
|
|
|
using (var conn = U8.U8LoginContext.Instance.Connection)
|
2021-04-29 13:55:18 +08:00
|
|
|
|
{
|
2021-04-30 11:51:19 +08:00
|
|
|
|
|
|
|
|
|
|
return conn.Query<NX.ERP.Model.PmcInventoryallRes>(sql, new { cinvcode = info.InvCodes, cInvStd = $"%{info.InvStd}%" });
|
2021-04-29 13:55:18 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2021-04-30 11:51:19 +08:00
|
|
|
|
public IEnumerable<object> Inventorymom(List<string> invCodes)
|
2021-04-29 13:55:18 +08:00
|
|
|
|
{
|
|
|
|
|
|
string sql = $@"
|
|
|
|
|
|
SELECT m..mocode, md.SortSeq, md.InvCode, p.cInvName, p.cInvStd,KK.cComUnitName, md.Qty, md.QualifiedInQty, ma.InvCode invcode1,
|
|
|
|
|
|
c.cInvName cinvname1, c.cInvStd cinvstd1,LL.cComUnitName, CASE WHEN c.bPurchase = 1 AND
|
|
|
|
|
|
c.bProxyForeign = 1 THEN '委外' WHEN c.bPurchase = 1 THEN '外购' WHEN c.bself = 1 THEN '自制' ELSE '其它' END AS
|
|
|
|
|
|
std, ma.Qty qty1, ma.IssQty issqty, mas.wqty wqty, ISNULL(cs.qty, 0) cqty, ISNULL(misss.issqty, 0) issqtyxc,ISNULL(ds.qty, 0) dqty,isnull(prd.Rqty, 0) rqty,
|
|
|
|
|
|
ISNULL(OMM.RQTY1, 0) AS rqty1, ISNULL(pu_App.RQTY3, 0) AS rqty3,ISNULL(momq.momqty, 0) AS momqty, ISNULL(MX.MQTY, 0) MQTY, mas.wqty - isnull(cs.qty, 0) - ISNULL(prd.Rqty, 0)
|
|
|
|
|
|
- ISNULL(omm.RQTY1, 0) - ISNULL(MX.MQTY, 0) AS q,
|
|
|
|
|
|
CASE WHEN md.Status = 2 THEN '锁定' WHEN md.Status = 3 THEN '审核' ELSE '新建' END AS st
|
|
|
|
|
|
FROM mom_order m INNER JOIN
|
|
|
|
|
|
mom_orderdetail md ON m.MoId = md.MoId INNER JOIN
|
|
|
|
|
|
mom_moallocate ma ON md.MoDId = ma.MoDId
|
|
|
|
|
|
INNER JOIN
|
|
|
|
|
|
(SELECT ma.invcode, SUM(isnull(ma.qty, 0) - isnull(issqty, 0)) wqty
|
|
|
|
|
|
FROM mom_moallocate ma INNER JOIN
|
|
|
|
|
|
mom_orderdetail md ON ma.MoDId = md.MoDId
|
|
|
|
|
|
WHERE md.Status <> 4 AND ma.Qty - ISNULL(ma.IssQty, 0) > 0
|
|
|
|
|
|
GROUP BY ma.InvCode) mas ON ma.InvCode = mas.InvCode LEFT JOIN
|
|
|
|
|
|
(SELECT ma.invcode, SUM( isnull(issqty, 0)) issqty
|
|
|
|
|
|
FROM mom_moallocate ma INNER JOIN
|
|
|
|
|
|
mom_orderdetail md ON ma.MoDId = md.MoDId
|
|
|
|
|
|
WHERE md.Status <> 4
|
|
|
|
|
|
GROUP BY ma.InvCode) misss ON ma.InvCode = misss.InvCode LEFT JOIN
|
|
|
|
|
|
(SELECT cinvcode, SUM(iquantity) qty
|
|
|
|
|
|
FROM currentstock
|
|
|
|
|
|
GROUP BY cInvCode) cs ON ma.InvCode = cs.cInvCode
|
|
|
|
|
|
LEFT JOIN
|
|
|
|
|
|
(SELECT cinvcode, SUM(iquantity) qty
|
|
|
|
|
|
FROM InvPositionSum where cPosCode not in ('00701','00801','09001')
|
|
|
|
|
|
GROUP BY cInvCode) ds ON ma.InvCode = ds.cInvCode
|
|
|
|
|
|
INNER JOIN
|
|
|
|
|
|
Inventory p ON md.InvCode = p.cInvCode INNER JOIN
|
|
|
|
|
|
Inventory c ON ma.InvCode = c.cInvCode LEFT JOIN
|
|
|
|
|
|
(SELECT MD.INVCODE, SUM(MD.QTY - ISNULL(MD.QUALIFIEDINQTY, 0)) AS MQTY
|
|
|
|
|
|
FROM mom_orderdetail MD
|
|
|
|
|
|
GROUP BY MD.INVCODE) MX ON MA.InvCode = MX.InvCode LEFT JOIN
|
|
|
|
|
|
(SELECT cinvcode, SUM(rqty) AS rqty
|
|
|
|
|
|
FROM (SELECT PDS.cInvCode, PDS.iQuantity - ISNULL(rds.qty, 0) AS Rqty
|
|
|
|
|
|
FROM PO_Pomain PM WITH (NOLOCK) INNER JOIN
|
|
|
|
|
|
PO_Podetails PDS WITH (NOLOCK) ON PM.POID = PDS.POID LEFT JOIN
|
|
|
|
|
|
(SELECT IPOSID, SUM(IQUANTITY) AS QTY
|
|
|
|
|
|
FROM rdrecords01 rds WITH (NOLOCK) INNER JOIN
|
|
|
|
|
|
RdRecord01 rd WITH (nolock) ON rds.ID = rd.ID
|
|
|
|
|
|
WHERE CBUSTYPE = '普通采购'
|
|
|
|
|
|
GROUP BY IPOSID) RDS ON PDS.ID = RDS.iPOsID
|
|
|
|
|
|
WHERE ISNULL(PM.CCLOSER, N'') = N'' AND ISNULL(PDS.CBCLOSER, N'') = N'' AND
|
|
|
|
|
|
pds.iQuantity - ISNULL(rds.qty, 0) > 0) x
|
|
|
|
|
|
GROUP BY cInvCode) prd ON ma.InvCode = prd.cInvCode LEFT JOIN
|
|
|
|
|
|
(SELECT CINVCODE, SUM(RQTY) AS RQTY1
|
|
|
|
|
|
FROM (SELECT ommds.cInvCode, ommds.iQuantity - ISNULL(rds.qty, 0) AS rqty
|
|
|
|
|
|
FROM OM_MOMain omm WITH (nolock) INNER JOIN
|
|
|
|
|
|
OM_MODetails ommds WITH (nolock) ON omm.MOID = ommds.MOID LEFT JOIN
|
|
|
|
|
|
(SELECT iomodid, sum(iquantity) AS qty
|
|
|
|
|
|
FROM rdrecords01 WITH (nolock)
|
|
|
|
|
|
GROUP BY iOMoDID) rds ON ommds.MODetailsID = rds.iOMoDID
|
|
|
|
|
|
WHERE ISNULL(OMM.cCloser, N'') = N'' AND ISNULL(ommds.cbCloser, N'') = N'' AND
|
|
|
|
|
|
ommds.iQuantity - ISNULL(rds.qty, 0) > 0) OM
|
|
|
|
|
|
GROUP BY cInvCode) OMM ON MA.INVCODE = OMM.CINVCODE LEFT JOIN
|
|
|
|
|
|
(SELECT CINVCODE, SUM(RQTY) AS RQTY3
|
|
|
|
|
|
FROM (SELECT ommds.cInvCode, ommds.fquantity - ISNULL(rds.qty, 0) 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 ommds.autoid = rds.iAppIds
|
|
|
|
|
|
WHERE ISNULL(OMM.cCloser, N'') = N'' AND ISNULL(ommds.cbCloser, N'') = N'' AND
|
|
|
|
|
|
ommds.fquantity - ISNULL(rds.qty, 0) > 0) OM
|
|
|
|
|
|
GROUP BY cInvCode) pu_App ON MA.INVCODE = pu_App.CINVCODE LEFT JOIN
|
|
|
|
|
|
(select InvCode,sum(qty) as momqty from mom_orderdetail where Status=3 group by InvCode) momq on MA.INVCODE = momq.InvCode
|
|
|
|
|
|
left join ComputationUnit kk WITH (nolock) on p.cComUnitCode=kk.cComunitCode
|
|
|
|
|
|
left join ComputationUnit LL WITH (nolock) on c.cComUnitCode=LL.cComunitCode
|
|
|
|
|
|
WHERE md.Status <> 4 AND ma.Qty - IsNull(ma.IssQty, 0) > 0
|
|
|
|
|
|
and m..mocode in @ins
|
|
|
|
|
|
order by m.mocode
|
|
|
|
|
|
";
|
2021-04-30 11:51:19 +08:00
|
|
|
|
using (var conn = NX.ERP.U8.U8LoginContext.Instance.Connection)
|
2021-04-29 13:55:18 +08:00
|
|
|
|
{
|
2021-04-30 11:51:19 +08:00
|
|
|
|
return conn.Query<object>(sql, new { ins = invCodes });
|
2021-04-29 13:55:18 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2021-04-30 11:51:19 +08:00
|
|
|
|
public IEnumerable<object> Inventorymonth(NX.ERP.Model.Request.Inventoryall info1)
|
2021-04-29 19:56:30 +08:00
|
|
|
|
{
|
|
|
|
|
|
string sql = $@"
|
|
|
|
|
|
select a.cInvCode,c.cInvName,c.cInvStd,LL.cComUnitName , CASE WHEN c.bPurchase = 1 AND c.bProxyForeign = 1 THEN '委外' WHEN c.bPurchase = 1 THEN '外购' WHEN c.bself = 1 THEN '自制' ELSE '其它' END AS std
|
|
|
|
|
|
,isnull(mas.wqty,0) wqty, ISNULL(cs.qty, 0) cqty,ISNULL(misss.issqty, 0) issqty , ISNULL(ds.qty, 0) dqty,isnull(prd.Rqty, 0) rqty,
|
|
|
|
|
|
ISNULL(OMM.RQTY1, 0) AS rqty1, ISNULL(pu_App.RQTY3, 0) AS rqty3,ISNULL(momq.momqty, 0) AS momqty, ISNULL(MX.MQTY, 0) MQTY, isnull(mas.wqty,0) - isnull(cs.qty, 0) - ISNULL(prd.Rqty, 0)
|
|
|
|
|
|
- ISNULL(omm.RQTY1, 0) - ISNULL(MX.MQTY, 0) AS q,isnull(a0.iQuantity,0) as iQuantity00 ,isnull(a1.iQuantity,0) as iQuantity01,
|
|
|
|
|
|
isnull(a2.iQuantity,0) as iQuantity02,isnull(a3.iQuantity,0) as iQuantity03,isnull(a4.iQuantity,0) as iQuantity04,isnull(a5.iQuantity,0) as iQuantity05
|
|
|
|
|
|
from
|
|
|
|
|
|
(select a.cinvcode from rdrecords11 a left join rdrecord11 b on a.id=b.id
|
|
|
|
|
|
where convert(varchar,b.dDate,112) between convert(varchar,dateadd(day,-day(dateadd(month,-5,getdate()))+1,dateadd(month,-5,getdate())),112)
|
|
|
|
|
|
and convert(varchar,dateadd(day,-day(getdate()),dateadd(month,1,getdate())),112)
|
|
|
|
|
|
group by a.cinvcode) a full join
|
|
|
|
|
|
|
|
|
|
|
|
(select left(convert(varchar,getdate(),112),6) as month1 , a.cinvcode, sum(a.iQuantity) as iQuantity from rdrecords11 a left join rdrecord11 b 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)
|
|
|
|
|
|
group by a.cinvcode
|
|
|
|
|
|
) a0 on a.cInvCode=a0.cInvCode
|
|
|
|
|
|
full join
|
|
|
|
|
|
(select left(convert(varchar,dateadd(month,-1,getdate()),112),6) as month1 , a.cinvcode, sum(a.iQuantity) as iQuantity from rdrecords11 a left join rdrecord11 b 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
|
|
|
|
|
|
) a1 on a.cInvCode =a1.cInvCode
|
|
|
|
|
|
full join
|
|
|
|
|
|
(select left(convert(varchar,dateadd(month,-3,getdate()),112),6) as month1 , a.cinvcode, sum(a.iQuantity) as iQuantity from rdrecords11 a left join rdrecord11 b on a.id=b.id
|
|
|
|
|
|
where convert(varchar,b.dDate,112) between convert(varchar,dateadd(day,-day(dateadd(month,-3,getdate()))+1,dateadd(month,-3,getdate())),112)
|
|
|
|
|
|
and convert(varchar,dateadd(day,-day(dateadd(month,-3,getdate())),dateadd(month,1,dateadd(month,-3,getdate()))),112)
|
|
|
|
|
|
group by a.cinvcode
|
|
|
|
|
|
) a2 on a.cInvCode =a2.cInvCode
|
|
|
|
|
|
full join
|
|
|
|
|
|
(select left(convert(varchar,dateadd(month,-2,getdate()),112),6) as month1 , a.cinvcode, sum(a.iQuantity) as iQuantity from rdrecords11 a left join rdrecord11 b on a.id=b.id
|
|
|
|
|
|
where convert(varchar,b.dDate,112) between convert(varchar,dateadd(day,-day(dateadd(month,-2,getdate()))+1,dateadd(month,-2,getdate())),112)
|
|
|
|
|
|
and convert(varchar,dateadd(day,-day(dateadd(month,-2,getdate())),dateadd(month,1,dateadd(month,-2,getdate()))),112)
|
|
|
|
|
|
group by a.cinvcode
|
|
|
|
|
|
) a3 on a.cInvCode =a3.cInvCode
|
|
|
|
|
|
full join
|
|
|
|
|
|
(select left(convert(varchar,dateadd(month,-4,getdate()),112),6) as month1 , a.cinvcode, sum(a.iQuantity) as iQuantity from rdrecords11 a left join rdrecord11 b on a.id=b.id
|
|
|
|
|
|
where convert(varchar,b.dDate,112) between convert(varchar,dateadd(day,-day(dateadd(month,-4,getdate()))+1,dateadd(month,-4,getdate())),112)
|
|
|
|
|
|
and convert(varchar,dateadd(day,-day(dateadd(month,-4,getdate())),dateadd(month,1,dateadd(month,-4,getdate()))),112)
|
|
|
|
|
|
group by a.cinvcode
|
|
|
|
|
|
) a4 on a.cInvCode =a4.cInvCode
|
|
|
|
|
|
full join
|
|
|
|
|
|
(select left(convert(varchar,dateadd(month,-5,getdate()),112),6) as month1 , a.cinvcode, sum(a.iQuantity) as iQuantity from rdrecords11 a left join rdrecord11 b on a.id=b.id
|
|
|
|
|
|
where convert(varchar,b.dDate,112) between convert(varchar,dateadd(day,-day(dateadd(month,-5,getdate()))+1,dateadd(month,-5,getdate())),112)
|
|
|
|
|
|
and convert(varchar,dateadd(day,-day(dateadd(month,-5,getdate())),dateadd(month,1,dateadd(month,-5,getdate()))),112)
|
|
|
|
|
|
group by a.cinvcode
|
|
|
|
|
|
) a5 on a.cInvCode =a5.cInvCode
|
|
|
|
|
|
left join Inventory c WITH (nolock) on a.cInvCode=c.cInvCode left join
|
|
|
|
|
|
(SELECT ma.invcode, SUM(isnull(ma.qty, 0) - isnull(issqty, 0)) wqty
|
|
|
|
|
|
FROM mom_moallocate ma INNER JOIN
|
|
|
|
|
|
mom_orderdetail md ON ma.MoDId = md.MoDId
|
|
|
|
|
|
WHERE md.Status <> 4 AND ma.Qty - ISNULL(ma.IssQty, 0) > 0
|
|
|
|
|
|
GROUP BY ma.InvCode) mas ON c.cInvCode = mas.InvCode LEFT JOIN
|
|
|
|
|
|
(SELECT ma.invcode, SUM( isnull(issqty, 0)) issqty
|
|
|
|
|
|
FROM mom_moallocate ma INNER JOIN
|
|
|
|
|
|
mom_orderdetail md ON ma.MoDId = md.MoDId
|
|
|
|
|
|
WHERE md.Status <> 4
|
|
|
|
|
|
GROUP BY ma.InvCode) misss ON c.cInvCode = misss.InvCode LEFT JOIN
|
|
|
|
|
|
|
|
|
|
|
|
(SELECT cinvcode, SUM(iquantity) qty
|
|
|
|
|
|
FROM currentstock
|
|
|
|
|
|
GROUP BY cInvCode) cs ON c.cInvCode = cs.cInvCode
|
|
|
|
|
|
LEFT JOIN
|
|
|
|
|
|
(SELECT cinvcode, SUM(iquantity) qty
|
|
|
|
|
|
FROM InvPositionSum where cPosCode not in ('00701','00801','09001')
|
|
|
|
|
|
GROUP BY cInvCode) ds ON c.cInvCode = ds.cInvCode
|
|
|
|
|
|
LEFT JOIN
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
(SELECT MD.INVCODE, SUM(MD.QTY - ISNULL(MD.QUALIFIEDINQTY, 0)) AS MQTY
|
|
|
|
|
|
FROM mom_orderdetail MD
|
|
|
|
|
|
GROUP BY MD.INVCODE) MX ON c.cInvCode = MX.InvCode LEFT JOIN
|
|
|
|
|
|
(SELECT cinvcode, SUM(rqty) AS rqty
|
|
|
|
|
|
FROM (SELECT PDS.cInvCode, PDS.iQuantity - ISNULL(rds.qty, 0) AS Rqty
|
|
|
|
|
|
FROM PO_Pomain PM WITH (NOLOCK) INNER JOIN
|
|
|
|
|
|
PO_Podetails PDS WITH (NOLOCK) ON PM.POID = PDS.POID LEFT JOIN
|
|
|
|
|
|
(SELECT IPOSID, SUM(IQUANTITY) AS QTY
|
|
|
|
|
|
FROM rdrecords01 rds WITH (NOLOCK) INNER JOIN
|
|
|
|
|
|
RdRecord01 rd WITH (nolock) ON rds.ID = rd.ID
|
|
|
|
|
|
WHERE CBUSTYPE = '普通采购'
|
|
|
|
|
|
GROUP BY IPOSID) RDS ON PDS.ID = RDS.iPOsID
|
|
|
|
|
|
WHERE ISNULL(PM.CCLOSER, N'') = N'' AND ISNULL(PDS.CBCLOSER, N'') = N'' AND
|
|
|
|
|
|
pds.iQuantity - ISNULL(rds.qty, 0) > 0) x
|
|
|
|
|
|
GROUP BY cInvCode) prd ON c.cInvCode = prd.cInvCode LEFT JOIN
|
|
|
|
|
|
(SELECT CINVCODE, SUM(RQTY) AS RQTY1
|
|
|
|
|
|
FROM (SELECT ommds.cInvCode, ommds.iQuantity - ISNULL(rds.qty, 0) AS rqty
|
|
|
|
|
|
FROM OM_MOMain omm WITH (nolock) INNER JOIN
|
|
|
|
|
|
OM_MODetails ommds WITH (nolock) ON omm.MOID = ommds.MOID LEFT JOIN
|
|
|
|
|
|
(SELECT iomodid, sum(iquantity) AS qty
|
|
|
|
|
|
FROM rdrecords01 WITH (nolock)
|
|
|
|
|
|
GROUP BY iOMoDID) rds ON ommds.MODetailsID = rds.iOMoDID
|
|
|
|
|
|
WHERE ISNULL(OMM.cCloser, N'') = N'' AND ISNULL(ommds.cbCloser, N'') = N'' AND
|
|
|
|
|
|
ommds.iQuantity - ISNULL(rds.qty, 0) > 0) OM
|
|
|
|
|
|
GROUP BY cInvCode) OMM ON c.cInvCode = OMM.CINVCODE LEFT JOIN
|
|
|
|
|
|
(SELECT CINVCODE, SUM(RQTY) AS RQTY3
|
|
|
|
|
|
FROM (SELECT ommds.cInvCode, ommds.fquantity - ISNULL(rds.qty, 0) 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 ommds.autoid = rds.iAppIds
|
|
|
|
|
|
WHERE ISNULL(OMM.cCloser, N'') = N'' AND ISNULL(ommds.cbCloser, N'') = N'' AND
|
|
|
|
|
|
ommds.fquantity - ISNULL(rds.qty, 0) > 0) OM
|
|
|
|
|
|
GROUP BY cInvCode) pu_App ON c.cInvCode = pu_App.CINVCODE LEFT JOIN
|
|
|
|
|
|
(select InvCode,sum(qty) as momqty from mom_orderdetail where Status=3 group by InvCode) momq on c.cInvCode = momq.InvCode
|
|
|
|
|
|
|
|
|
|
|
|
left join ComputationUnit LL WITH (nolock) on c.cComUnitCode=LL.cComunitCode
|
|
|
|
|
|
|
|
|
|
|
|
";
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
List<string> where = new List<string>();
|
|
|
|
|
|
|
2021-04-30 11:51:19 +08:00
|
|
|
|
if (info1.InvCodes != null)
|
2021-04-29 19:56:30 +08:00
|
|
|
|
{
|
|
|
|
|
|
where.Add(" c.cinvcode in @cinvcode");
|
|
|
|
|
|
}
|
2021-04-30 11:51:19 +08:00
|
|
|
|
|
2021-04-29 19:56:30 +08:00
|
|
|
|
|
|
|
|
|
|
var aa = string.Join(" and ", where.ToArray());
|
|
|
|
|
|
|
|
|
|
|
|
if (!string.IsNullOrEmpty(aa))
|
|
|
|
|
|
{
|
|
|
|
|
|
sql += "where " + aa;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2021-04-30 11:51:19 +08:00
|
|
|
|
using (var conn = NX.ERP.U8.U8LoginContext.Instance.Connection)
|
2021-04-29 19:56:30 +08:00
|
|
|
|
{
|
2021-04-30 11:51:19 +08:00
|
|
|
|
return conn.Query<object>(sql, new { cinvcode = info1.InvCodes });
|
2021-04-29 19:56:30 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2021-04-30 11:51:19 +08:00
|
|
|
|
public IEnumerable<object> Inventorysocode(NX.ERP.Model.Request.Inventoryall info1)
|
2021-04-29 19:56:30 +08:00
|
|
|
|
{
|
|
|
|
|
|
string sql = $@"
|
|
|
|
|
|
select j.cSTName,b.cSOCode,b.dDate,a.iRowNo,f.cCusAbbName,a.cInvCode,a.cInvName,g.cInvStd,a.iQuantity,isnull( h.dDate,'') as fhdDate ,isnull(c.fqty,0)fqty,isnull(d.cqty,0)cqty
|
|
|
|
|
|
,isnull(cs.qty,0)qty,isnull(momq.momqty,0)momqty
|
|
|
|
|
|
from SO_SODetails a WITH (nolock) left join SO_SOMain b WITH (nolock) on a.ID=b.id
|
|
|
|
|
|
LEFT JOIN
|
|
|
|
|
|
(SELECT iSOsID, sum(iQuantity) AS fqty
|
|
|
|
|
|
FROM DispatchLists WITH (nolock)
|
|
|
|
|
|
GROUP BY iSOsID) c on a.iSOsID=c.iSOsID
|
|
|
|
|
|
LEFT JOIN
|
|
|
|
|
|
(SELECT ipesodid, sum(iQuantity) AS cqty
|
|
|
|
|
|
FROM rdrecords32 WITH (nolock)
|
|
|
|
|
|
GROUP BY ipesodid) d on d.ipesodid=a.iSOsID
|
|
|
|
|
|
left join
|
|
|
|
|
|
(SELECT cinvcode, SUM(iquantity) qty
|
|
|
|
|
|
FROM currentstock WITH (nolock)
|
|
|
|
|
|
GROUP BY cInvCode) cs ON a.cInvCode = cs.cInvCode
|
|
|
|
|
|
LEFT JOIN
|
|
|
|
|
|
(select InvCode,sum(qty) as momqty from mom_orderdetail WITH (nolock)
|
|
|
|
|
|
where Status=3 group by InvCode) momq on a.cInvCode = momq.InvCode
|
|
|
|
|
|
left join Customer f WITH (nolock) on b.cCusCode=f.cCusCode
|
|
|
|
|
|
left join Inventory g WITH (nolock) on g.cInvCode=a.cInvCode
|
|
|
|
|
|
left join DispatchList h WITH (nolock) on b.cSOCode =h.cSOCode
|
|
|
|
|
|
left join SaleType j WITH (nolock) on j.cSTCode=b.cSTCode
|
|
|
|
|
|
|
|
|
|
|
|
";
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
List<string> where = new List<string>();
|
|
|
|
|
|
|
2021-04-30 11:51:19 +08:00
|
|
|
|
if (info1.InvCodes != null)
|
2021-04-29 19:56:30 +08:00
|
|
|
|
{
|
|
|
|
|
|
where.Add(" a.cinvcode in @cinvcode");
|
|
|
|
|
|
}
|
2021-04-30 11:51:19 +08:00
|
|
|
|
if (!string.IsNullOrEmpty(info1.InvStd))
|
2021-04-29 19:56:30 +08:00
|
|
|
|
{
|
|
|
|
|
|
where.Add(" g.cInvStd like @cInvStd ");
|
|
|
|
|
|
}
|
2021-04-30 11:51:19 +08:00
|
|
|
|
if (!string.IsNullOrEmpty(info1.SoCode))
|
2021-04-29 19:56:30 +08:00
|
|
|
|
{
|
2021-04-30 11:51:19 +08:00
|
|
|
|
where.Add(" b.cSOCode like @cSOCode ");
|
2021-04-29 19:56:30 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
var aa = string.Join(" and ", where.ToArray());
|
|
|
|
|
|
|
|
|
|
|
|
if (!string.IsNullOrEmpty(aa))
|
|
|
|
|
|
{
|
|
|
|
|
|
sql += "where " + aa;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2021-04-30 11:51:19 +08:00
|
|
|
|
using (var conn = NX.ERP.U8.U8LoginContext.Instance.Connection)
|
2021-04-29 19:56:30 +08:00
|
|
|
|
{
|
2021-04-30 11:51:19 +08:00
|
|
|
|
return conn.Query<object>(sql, new { cinvcode = info1.InvCodes, cInvStd = $"%{info1.InvStd}%", cSOCode = $"%{info1.SoCode}%" });
|
2021-04-29 19:56:30 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2021-04-29 13:55:18 +08:00
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|