Files
U8-Import/NX.ERP.U8/Pmc/PmcQuery.cs

1191 lines
74 KiB
C#
Raw Normal View History

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 = $@"
2021-05-26 17:05:28 +08:00
SELECT c.cInvCode invcode1,
2021-05-25 00:40:12 +08:00
c.cInvName cinvname1, c.cInvStd cinvstd1,LL.cComUnitName, CASE
2021-05-28 09:23:02 +08:00
WHEN c.bPurchase = 1 AND c.bProxyForeign = 1 and c.bself = 1 THEN '外购,委外,自制'
WHEN c.bPurchase = 1 AND c.bProxyForeign = 1 and c.bself <>1 THEN '外购,委外'
2021-05-25 00:40:12 +08:00
WHEN c.bPurchase = 1 AND c.bProxyForeign <> 1 and c.bself <> 1 THEN '外购'
WHEN c.bPurchase = 1 AND c.bProxyForeign <> 1 and c.bself = 1 THEN '外购,自制'
WHEN c.bPurchase <> 1 AND c.bProxyForeign <> 1 and c.bself = 1 THEN '自制'
2021-05-28 09:23:02 +08:00
WHEN c.bPurchase <> 1 AND c.bProxyForeign = 1 and c.bself = 1 THEN '委外,自制'
WHEN c.bPurchase <> 1 AND c.bProxyForeign = 1 and c.bself <> 1 THEN '委外'
2021-05-25 00:40:12 +08:00
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,
2021-05-26 17:05:28 +08:00
ISNULL(OMM.RQTY1, 0) AS rqty1, ISNULL(pu_App.RQTY3, 0) AS rqty3,ISNULL(MX.MQTY, 0) as momqty,0-(isnull(mas.wqty,0) - isnull(ds.qty, 0) - ISNULL(prd.Rqty, 0)
- ISNULL(omm.RQTY1, 0) - ISNULL(MX.MQTY, 0)- ISNULL(pu_App.RQTY3, 0)) AS q ,ven.cVenAbbName, cma.cMaker
2021-04-29 13:55:18 +08:00
2021-05-06 11:35:41 +08:00
FROM Inventory c WITH (NOLOCK) LEFT JOIN
2021-04-29 13:55:18 +08:00
(SELECT ma.invcode, SUM(isnull(ma.qty, 0) - isnull(issqty, 0)) wqty
2021-05-06 11:35:41 +08:00
FROM mom_moallocate ma WITH (NOLOCK) INNER JOIN
mom_orderdetail md WITH (NOLOCK) ON ma.MoDId = md.MoDId
2021-04-29 13:55:18 +08:00
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
2021-05-06 11:35:41 +08:00
FROM mom_moallocate ma WITH (NOLOCK) INNER JOIN
mom_orderdetail md WITH (NOLOCK) ON ma.MoDId = md.MoDId
2021-04-29 13:55:18 +08:00
WHERE md.Status <> 4
GROUP BY ma.InvCode) misss ON c.cInvCode = misss.InvCode LEFT JOIN
(SELECT cinvcode, SUM(iquantity) qty
2021-05-06 11:35:41 +08:00
FROM currentstock WITH (NOLOCK)
2021-04-29 13:55:18 +08:00
GROUP BY cInvCode) cs ON c.cInvCode = cs.cInvCode
LEFT JOIN
(SELECT cinvcode, SUM(iquantity) qty
2021-08-16 15:24:37 +08:00
FROM InvPositionSum WITH (NOLOCK) where cPosCode not in ('00701','00801','09001') and cWhCode not in (4,5)
2021-04-29 13:55:18 +08:00
GROUP BY cInvCode) ds ON c.cInvCode = ds.cInvCode
LEFT JOIN
(SELECT MD.INVCODE, SUM(MD.QTY - ISNULL(MD.QUALIFIEDINQTY, 0)) AS MQTY
2021-05-06 11:35:41 +08:00
FROM mom_orderdetail MD WITH (NOLOCK)
2021-04-29 13:55:18 +08:00
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
2021-05-26 17:05:28 +08:00
GROUP BY cInvCode) pu_App ON c.cInvCode = pu_App.CINVCODE
2021-04-29 13:55:18 +08:00
left join ComputationUnit LL WITH (nolock) on c.cComUnitCode=LL.cComunitCode
2021-05-26 17:05:28 +08:00
left join (
select a.*,b.cVenAbbName From (
select cInvCode,cVenCode from ( select cInvCode,ROW_NUMBER() over( partition by b.cInvCode order by a.poid desc) as rownumber ,a.cVenCode
from PO_Pomain a WITH (nolock), PO_Podetails b WITH (nolock) where a.poid=b.poid)
as c where c.rownumber=1 ) a left join Vendor b WITH (nolock) on a.cVenCode= b.cVenCode ) ven on c.cInvCode = ven.cInvCode
left join (
select cInvCode, ISNULL(b.cPsn_Name,'其他') as cMaker from
(
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) a left join (
select cPsn_Num, cPsn_Name from hr_v_HR31_show WITH (nolock) where cDepCode ='52' and rEmployState ='在职') b on a.cMaker =b.cPsn_Name
) cma on c.cInvCode = cma.cInvCode ";
2021-04-29 13:55:18 +08:00
List<string> where = new List<string>();
2021-05-21 09:50:57 +08:00
//处理-
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-05-04 13:50:12 +08:00
2021-05-04 14:43:24 +08:00
2021-05-04 13:50:12 +08:00
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-05-18 20:27:36 +08:00
public IEnumerable<NX.ERP.Model.PmcInventorymomRes> Inventorymom(NX.ERP.Model.Request.MomOrderRequest info)
2021-04-29 13:55:18 +08:00
{
string sql = $@"
2021-05-18 14:52:39 +08:00
select *from (
2021-05-26 17:05:28 +08:00
SELECT m..mocode,CONVERT(varchar(100), mor.StartDate, 23) as StartDate ,md.Remark,CONVERT(varchar(100), mor.DueDate, 23) as DueDate ,DATEDIFF(day,GETDATE(),mor.DueDate) AS jandete , md.SortSeq, md.InvCode, p.cInvName, p.cInvStd,KK.cComUnitName, md.Qty, md.QualifiedInQty,(md.Qty-md.QualifiedInQty) as wwc, ma.InvCode invcode1,
2021-05-25 00:40:12 +08:00
c.cInvName cinvname1, c.cInvStd cinvstd1,LL.cComUnitName as cComUnitName1, CASE
2021-05-28 09:23:02 +08:00
WHEN c.bPurchase = 1 AND c.bProxyForeign = 1 and c.bself = 1 THEN '外购,委外,自制'
WHEN c.bPurchase = 1 AND c.bProxyForeign = 1 and c.bself <>1 THEN '外购,委外'
WHEN c.bPurchase = 1 AND c.bProxyForeign <> 1 and c.bself <> 1 THEN '外购'
WHEN c.bPurchase = 1 AND c.bProxyForeign <> 1 and c.bself = 1 THEN '外购,自制'
WHEN c.bPurchase <> 1 AND c.bProxyForeign <> 1 and c.bself = 1 THEN '自制'
WHEN c.bPurchase <> 1 AND c.bProxyForeign = 1 and c.bself = 1 THEN '委外,自制'
WHEN c.bPurchase <> 1 AND c.bProxyForeign = 1 and c.bself <> 1 THEN '委外'
2021-05-25 00:40:12 +08:00
ELSE '其它'
END AS std,dtyl.dtty, ma.Qty qty1, ma.IssQty issqty,(ma.Qty-ma.IssQty) as wll,mdsss.mdqty,shwl.shwl,sdwl.sdwl
,mas.wqty wqty, ISNULL(cs.qty, 0) cqty, ISNULL(misss.issqty, 0) issqtyxc,ISNULL(ds.qty, 0) dqty,isnull(prd.Rqty, 0) rqty,
2021-05-26 17:05:28 +08:00
ISNULL(OMM.RQTY1, 0) AS rqty1, ISNULL(pu_App.RQTY3, 0) AS rqty3,ISNULL(MX.MQTY, 0) momqty, 0-(isnull(mas.wqty,0) - isnull(ds.qty, 0) - ISNULL(prd.Rqty, 0)
2021-05-25 00:40:12 +08:00
- ISNULL(omm.RQTY1, 0) - ISNULL(MX.MQTY, 0)- ISNULL(pu_App.RQTY3, 0)) AS q, motype.description,
2021-05-20 08:50:37 +08:00
CASE WHEN md.Status = 2 THEN '锁定' WHEN md.Status = 4 THEN '关闭' WHEN md.Status = 3 THEN '审核' ELSE '新建' END AS st, md.Status
2021-05-06 11:35:41 +08:00
FROM mom_order m WITH (NOLOCK) INNER JOIN
2021-05-22 20:22:13 +08:00
mom_orderdetail md WITH (NOLOCK) ON m.MoId = md.MoId INNER JOIN
mom_morder mor WITH (NOLOCK) ON md.MoDId = mor.MoDId INNER JOIN
2021-05-06 11:35:41 +08:00
mom_moallocate ma WITH (NOLOCK) ON md.MoDId = ma.MoDId
2021-05-21 09:32:30 +08:00
left JOIN
2021-05-20 08:50:37 +08:00
mom_motype motype WITH (NOLOCK) ON motype.MoTypeId = md.MoTypeId
2021-06-29 16:12:29 +08:00
left JOIN
2021-04-29 13:55:18 +08:00
(SELECT ma.invcode, SUM(isnull(ma.qty, 0) - isnull(issqty, 0)) wqty
2021-05-06 11:35:41 +08:00
FROM mom_moallocate ma WITH (NOLOCK) INNER JOIN
mom_orderdetail md WITH (NOLOCK) ON ma.MoDId = md.MoDId
2021-04-29 13:55:18 +08:00
WHERE md.Status <> 4 AND ma.Qty - ISNULL(ma.IssQty, 0) > 0
GROUP BY ma.InvCode) mas ON ma.InvCode = mas.InvCode LEFT JOIN
2021-05-06 11:35:41 +08:00
2021-05-18 20:27:36 +08:00
(SELECT ma.invcode,SUM(isnull(ma.qty, 0) - isnull(issqty, 0)) mdqty
2021-05-06 11:35:41 +08:00
FROM mom_moallocate ma WITH (NOLOCK) INNER JOIN
mom_orderdetail md WITH (NOLOCK) ON ma.MoDId = md.MoDId left join
mom_order mom WITH (NOLOCK) on md.MoId=mom.MoId
2021-05-18 14:52:39 +08:00
WHERE md.Status <> 4
2021-05-18 20:27:36 +08:00
GROUP BY ma.InvCode) mdsss ON ma.InvCode = mdsss.InvCode LEFT JOIN
2021-05-06 11:35:41 +08:00
2021-05-22 20:22:13 +08:00
(SELECT ma.invcode,SUM(isnull(ma.qty, 0) - isnull(issqty, 0)) sdwl
FROM mom_moallocate ma WITH (NOLOCK) INNER JOIN
mom_orderdetail md WITH (NOLOCK) ON ma.MoDId = md.MoDId left join
mom_order mom WITH (NOLOCK) on md.MoId=mom.MoId
WHERE md.Status = 2
GROUP BY ma.InvCode) sdwl ON ma.InvCode = sdwl.InvCode LEFT JOIN
(SELECT ma.invcode,SUM(isnull(ma.qty, 0) - isnull(issqty, 0)) shwl
FROM mom_moallocate ma WITH (NOLOCK) INNER JOIN
mom_orderdetail md WITH (NOLOCK) ON ma.MoDId = md.MoDId left join
mom_order mom WITH (NOLOCK) on md.MoId=mom.MoId
WHERE md.Status = 3
GROUP BY ma.InvCode) shwl ON ma.InvCode = shwl.InvCode LEFT JOIN
2021-06-29 16:12:29 +08:00
(select a.MoCode ,a.InvCode ,a.MoDId ,(a.dtty/b.Qty) as dtty from (
SELECT mom.MoCode, ma.invcode,round(SUM(isnull(ma.qty, 0)),3) dtty, md.MoDId
2021-05-22 20:22:13 +08:00
FROM mom_moallocate ma WITH (NOLOCK) INNER JOIN
mom_orderdetail md WITH (NOLOCK) ON ma.MoDId = md.MoDId left join
2021-06-29 16:12:29 +08:00
mom_order mom WITH (NOLOCK) on md.MoId=mom.MoId
GROUP BY ma.InvCode,mom.MoCode, md.MoDId ) a left join mom_orderdetail b WITH (NOLOCK) ON a.MoDId = b.MoDId ) dtyl ON ma.InvCode = dtyl.InvCode and dtyl.MoCode=m.MoCode and md.MoDId= dtyl.MoDId
LEFT JOIN
2021-05-22 20:22:13 +08:00
2021-04-29 13:55:18 +08:00
(SELECT ma.invcode, SUM( isnull(issqty, 0)) issqty
2021-05-06 11:35:41 +08:00
FROM mom_moallocate ma WITH (NOLOCK) INNER JOIN
mom_orderdetail md WITH (NOLOCK) ON ma.MoDId = md.MoDId
2021-04-29 13:55:18 +08:00
WHERE md.Status <> 4
GROUP BY ma.InvCode) misss ON ma.InvCode = misss.InvCode LEFT JOIN
(SELECT cinvcode, SUM(iquantity) qty
2021-05-06 11:35:41 +08:00
FROM currentstock WITH (NOLOCK)
2021-04-29 13:55:18 +08:00
GROUP BY cInvCode) cs ON ma.InvCode = cs.cInvCode
LEFT JOIN
(SELECT cinvcode, SUM(iquantity) qty
2021-08-16 15:24:37 +08:00
FROM InvPositionSum WITH (NOLOCK) where cPosCode not in ('00701','00801','09001') and cWhCode not in (4,5)
2021-04-29 13:55:18 +08:00
GROUP BY cInvCode) ds ON ma.InvCode = ds.cInvCode
INNER JOIN
2021-05-06 11:35:41 +08:00
Inventory p WITH (NOLOCK) ON md.InvCode = p.cInvCode INNER JOIN
Inventory c WITH (NOLOCK) ON ma.InvCode = c.cInvCode LEFT JOIN
2021-04-29 13:55:18 +08:00
(SELECT MD.INVCODE, SUM(MD.QTY - ISNULL(MD.QUALIFIEDINQTY, 0)) AS MQTY
2021-05-06 11:35:41 +08:00
FROM mom_orderdetail MD WITH (NOLOCK)
2021-04-29 13:55:18 +08:00
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)
2021-08-16 15:24:37 +08:00
GROUP BY iAppIds
union all
SELECT cupsoids as iAppIds , sum(iquantity) AS qty
FROM OM_MODetails WITH (nolock)
GROUP BY cupsoids
) rds ON ommds.autoid = rds.iAppIds
2021-04-29 13:55:18 +08:00
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
2021-05-06 11:35:41 +08:00
(select InvCode,sum(qty) as momqty from mom_orderdetail WITH (NOLOCK) where Status=3 group by InvCode) momq on MA.INVCODE = momq.InvCode
2021-04-29 13:55:18 +08:00
left join ComputationUnit kk WITH (nolock) on p.cComUnitCode=kk.cComunitCode
left join ComputationUnit LL WITH (nolock) on c.cComUnitCode=LL.cComunitCode
2021-05-18 20:27:36 +08:00
) mmm
2021-04-29 13:55:18 +08:00
";
2021-05-18 14:52:39 +08:00
2021-05-18 20:27:36 +08:00
if (info.moCodes != null && info.moCodes.Count > 0)
{
sql = $@"
select *from (
2021-05-26 17:05:28 +08:00
SELECT m..mocode,CONVERT(varchar(100), mor.StartDate, 23) as StartDate,md.Remark ,CONVERT(varchar(100), mor.DueDate, 23) as DueDate ,DATEDIFF(day,GETDATE(),mor.DueDate) AS jandete , md.SortSeq, md.InvCode, p.cInvName, p.cInvStd,KK.cComUnitName, md.Qty, md.QualifiedInQty,(md.Qty-md.QualifiedInQty) as wwc, ma.InvCode invcode1,
2021-05-25 00:40:12 +08:00
c.cInvName cinvname1, c.cInvStd cinvstd1,LL.cComUnitName as cComUnitName1,CASE
2021-05-28 09:23:02 +08:00
WHEN c.bPurchase = 1 AND c.bProxyForeign = 1 and c.bself = 1 THEN '外购,委外,自制'
WHEN c.bPurchase = 1 AND c.bProxyForeign = 1 and c.bself <>1 THEN '外购,委外'
WHEN c.bPurchase = 1 AND c.bProxyForeign <> 1 and c.bself <> 1 THEN '外购'
WHEN c.bPurchase = 1 AND c.bProxyForeign <> 1 and c.bself = 1 THEN '外购,自制'
WHEN c.bPurchase <> 1 AND c.bProxyForeign <> 1 and c.bself = 1 THEN '自制'
WHEN c.bPurchase <> 1 AND c.bProxyForeign = 1 and c.bself = 1 THEN '委外,自制'
WHEN c.bPurchase <> 1 AND c.bProxyForeign = 1 and c.bself <> 1 THEN '委外'
2021-05-25 00:40:12 +08:00
ELSE '其它'
END AS std,dtyl.dtty, ma.Qty qty1, ma.IssQty issqty,(ma.Qty-ma.IssQty) as wll,mdsss.mdqty,shwl.shwl,sdwl.sdwl
2021-05-22 20:22:13 +08:00
,mas.wqty wqty, ISNULL(cs.qty, 0) cqty, ISNULL(misss.issqty, 0) issqtyxc,ISNULL(ds.qty, 0) dqty,isnull(prd.Rqty, 0) rqty,
2021-05-26 17:05:28 +08:00
ISNULL(OMM.RQTY1, 0) AS rqty1, ISNULL(pu_App.RQTY3, 0) AS rqty3,ISNULL(MX.MQTY, 0) momqty, 0-(isnull(mas.wqty,0) - isnull(ds.qty, 0) - ISNULL(prd.Rqty, 0)
2021-05-25 00:40:12 +08:00
- ISNULL(omm.RQTY1, 0) - ISNULL(MX.MQTY, 0)- ISNULL(pu_App.RQTY3, 0)) AS q, motype.description,
2021-05-20 08:50:37 +08:00
CASE WHEN md.Status = 2 THEN '锁定' WHEN md.Status = 4 THEN '关闭' WHEN md.Status = 3 THEN '审核' ELSE '新建' END AS st, md.Status
2021-05-18 20:27:36 +08:00
FROM mom_order m WITH (NOLOCK) INNER JOIN
2021-05-22 20:22:13 +08:00
mom_orderdetail md WITH (NOLOCK) ON m.MoId = md.MoId INNER JOIN
mom_morder mor WITH (NOLOCK) ON md.MoDId = mor.MoDId INNER JOIN
2021-05-18 20:27:36 +08:00
mom_moallocate ma WITH (NOLOCK) ON md.MoDId = ma.MoDId
2021-05-21 09:32:30 +08:00
left JOIN
2021-05-22 20:22:13 +08:00
mom_motype motype WITH (NOLOCK) ON motype.MoTypeId = md.MoTypeId
2021-06-29 16:12:29 +08:00
left JOIN
2021-05-18 20:27:36 +08:00
(SELECT ma.invcode, SUM(isnull(ma.qty, 0) - isnull(issqty, 0)) wqty
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) mas ON ma.InvCode = mas.InvCode LEFT JOIN
(SELECT ma.invcode,SUM(isnull(ma.qty, 0) - isnull(issqty, 0)) mdqty
FROM mom_moallocate ma WITH (NOLOCK) INNER JOIN
mom_orderdetail md WITH (NOLOCK) ON ma.MoDId = md.MoDId left join
mom_order mom WITH (NOLOCK) on md.MoId=mom.MoId
WHERE md.Status <> 4 and mom.mocode in @moCodes
GROUP BY ma.InvCode) mdsss ON ma.InvCode = mdsss.InvCode LEFT JOIN
2021-05-22 20:22:13 +08:00
(SELECT ma.invcode,SUM(isnull(ma.qty, 0) - isnull(issqty, 0)) sdwl
FROM mom_moallocate ma WITH (NOLOCK) INNER JOIN
mom_orderdetail md WITH (NOLOCK) ON ma.MoDId = md.MoDId left join
mom_order mom WITH (NOLOCK) on md.MoId=mom.MoId
WHERE md.Status = 2
GROUP BY ma.InvCode) sdwl ON ma.InvCode = sdwl.InvCode LEFT JOIN
(SELECT ma.invcode,SUM(isnull(ma.qty, 0) - isnull(issqty, 0)) shwl
FROM mom_moallocate ma WITH (NOLOCK) INNER JOIN
mom_orderdetail md WITH (NOLOCK) ON ma.MoDId = md.MoDId left join
mom_order mom WITH (NOLOCK) on md.MoId=mom.MoId
WHERE md.Status = 3
GROUP BY ma.InvCode) shwl ON ma.InvCode = shwl.InvCode LEFT JOIN
2021-06-29 16:12:29 +08:00
(select a.MoCode ,a.InvCode ,a.MoDId ,(a.dtty/b.Qty) as dtty from (
SELECT mom.MoCode, ma.invcode,round(SUM(isnull(ma.qty, 0)),3) dtty, md.MoDId
2021-05-22 20:22:13 +08:00
FROM mom_moallocate ma WITH (NOLOCK) INNER JOIN
mom_orderdetail md WITH (NOLOCK) ON ma.MoDId = md.MoDId left join
2021-06-29 16:12:29 +08:00
mom_order mom WITH (NOLOCK) on md.MoId=mom.MoId
GROUP BY ma.InvCode,mom.MoCode, md.MoDId ) a left join mom_orderdetail b WITH (NOLOCK) ON a.MoDId = b.MoDId ) dtyl ON ma.InvCode = dtyl.InvCode and dtyl.MoCode=m.MoCode and md.MoDId= dtyl.MoDId
LEFT JOIN
2021-05-22 20:22:13 +08:00
2021-05-18 20:27:36 +08:00
(SELECT ma.invcode, SUM( isnull(issqty, 0)) issqty
FROM mom_moallocate ma WITH (NOLOCK) INNER JOIN
mom_orderdetail md WITH (NOLOCK) 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 WITH (NOLOCK)
GROUP BY cInvCode) cs ON ma.InvCode = cs.cInvCode
LEFT JOIN
(SELECT cinvcode, SUM(iquantity) qty
2021-08-16 15:24:37 +08:00
FROM InvPositionSum WITH (NOLOCK) where cPosCode not in ('00701','00801','09001') and cWhCode not in (4,5)
2021-05-18 20:27:36 +08:00
GROUP BY cInvCode) ds ON ma.InvCode = ds.cInvCode
INNER JOIN
Inventory p WITH (NOLOCK) ON md.InvCode = p.cInvCode INNER JOIN
Inventory c WITH (NOLOCK) ON ma.InvCode = c.cInvCode LEFT JOIN
(SELECT MD.INVCODE, SUM(MD.QTY - ISNULL(MD.QUALIFIEDINQTY, 0)) AS MQTY
FROM mom_orderdetail MD WITH (NOLOCK)
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)
2021-08-16 15:24:37 +08:00
GROUP BY iAppIds
union all
SELECT cupsoids as iAppIds , sum(iquantity) AS qty
FROM OM_MODetails WITH (nolock)
GROUP BY cupsoids
) rds ON ommds.autoid = rds.iAppIds
2021-05-18 20:27:36 +08:00
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 WITH (NOLOCK) 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
) mmm
";
}
List<string> where = new List<string>();
2021-05-18 14:52:39 +08:00
///处理-
2021-05-18 20:27:36 +08:00
if (info.moCodes != null && info.moCodes.Count > 0)
2021-05-18 14:52:39 +08:00
{
where.Add(" mmm.mocode in @moCodes");
}
2021-05-22 16:38:37 +08:00
if (info.InvCodes != null)
{
where.Add(" mmm.InvCode in @invcode");
}
if (info.InvCodes1!= null )
2021-05-18 20:27:36 +08:00
{
where.Add(" mmm.invcode1 in @invcode1");
}
2021-05-22 16:38:37 +08:00
if (info.byFinish != null)
2021-05-18 20:27:36 +08:00
{
2021-05-22 16:38:37 +08:00
where.Add(" mmm.Status in @byFinish");
2021-05-18 20:27:36 +08:00
}
if (!info.byiss)
{
where.Add(" isnull(mmm.qty1,0)- isnull(mmm.issqty,0)> 0");
}
else { where.Add(" mmm.issqty > 0"); }
2021-05-18 14:52:39 +08:00
var aa = string.Join(" and ", where.ToArray());
if (!string.IsNullOrEmpty(aa))
{
sql += "where " + aa;
}
2021-05-22 20:22:13 +08:00
using (var conn = NX.ERP.U8.U8LoginContext.Instance.Connection )
2021-04-29 13:55:18 +08:00
{
2021-05-22 16:38:37 +08:00
return conn.Query<NX.ERP.Model.PmcInventorymomRes>(sql, new { moCodes = info.moCodes, invcode = info.InvCodes, invcode1=info.InvCodes1, info.byFinish });
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 = $@"
2021-05-28 09:23:02 +08:00
IF EXISTS (SELECT NAME FROM tempdb..SYSOBJECTS WHERE NAME ='tablepzck20210526' AND Xtype='U') DROP Table tempdb..tablepzck20210526
create table tempdb..tablepzck20210526 (
2021-05-26 17:05:28 +08:00
cInvCode nvarchar(120),
cInvName nvarchar(120),
cInvStd nvarchar(120),
cComUnitName nvarchar(120),
std nvarchar(120),
wqty decimal(28, 6),
cqty decimal(28, 6),
issqty decimal(28, 6),
dqty decimal(28, 6),
rqty decimal(28, 6),
rqty1 decimal(28, 6),
rqty3 decimal(28, 6),
momqty decimal(28, 6),
q decimal(28, 6),
iQuantity00 decimal(28, 6),
iQuantity01 decimal(28, 6),
iQuantity02 decimal(28, 6),
iQuantity03 decimal(28, 6),
iQuantity04 decimal(28, 6),
iQuantity05 decimal(28, 6)
)
2021-05-28 09:23:02 +08:00
insert into tempdb..tablepzck20210526
2021-05-26 17:05:28 +08:00
select a.cInvCode,c.cInvName,c.cInvStd,LL.cComUnitName ,
CASE
2021-05-28 09:23:02 +08:00
WHEN c.bPurchase = 1 AND c.bProxyForeign = 1 and c.bself = 1 THEN '外购,委外,自制'
WHEN c.bPurchase = 1 AND c.bProxyForeign = 1 and c.bself <>1 THEN '外购,委外'
WHEN c.bPurchase = 1 AND c.bProxyForeign <> 1 and c.bself <> 1 THEN '外购'
WHEN c.bPurchase = 1 AND c.bProxyForeign <> 1 and c.bself = 1 THEN '外购,自制'
WHEN c.bPurchase <> 1 AND c.bProxyForeign <> 1 and c.bself = 1 THEN '自制'
WHEN c.bPurchase <> 1 AND c.bProxyForeign = 1 and c.bself = 1 THEN '委外,自制'
WHEN c.bPurchase <> 1 AND c.bProxyForeign = 1 and c.bself <> 1 THEN '委外'
2021-05-26 17:05:28 +08:00
ELSE '其它'
END AS std,
0,0,0,
0,0,0,
0,0,0,
0,0,0,
0,0,0 from
(select a.cinvcode 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(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
left join Inventory c WITH (nolock) on a.cInvCode=c.cInvCode
left join ComputationUnit LL WITH (nolock) on c.cComUnitCode=LL.cComunitCode
2021-05-28 09:23:02 +08:00
insert into tempdb..tablepzck20210526
2021-05-26 17:05:28 +08:00
select a.cInvCode,c.cInvName,c.cInvStd,LL.cComUnitName ,
CASE
2021-05-28 09:23:02 +08:00
WHEN c.bPurchase = 1 AND c.bProxyForeign = 1 and c.bself = 1 THEN '外购,委外,自制'
WHEN c.bPurchase = 1 AND c.bProxyForeign = 1 and c.bself <>1 THEN '外购,委外'
WHEN c.bPurchase = 1 AND c.bProxyForeign <> 1 and c.bself <> 1 THEN '外购'
WHEN c.bPurchase = 1 AND c.bProxyForeign <> 1 and c.bself = 1 THEN '外购,自制'
WHEN c.bPurchase <> 1 AND c.bProxyForeign <> 1 and c.bself = 1 THEN '自制'
WHEN c.bPurchase <> 1 AND c.bProxyForeign = 1 and c.bself = 1 THEN '委外,自制'
WHEN c.bPurchase <> 1 AND c.bProxyForeign = 1 and c.bself <> 1 THEN '委外'
2021-05-26 17:05:28 +08:00
ELSE '其它'
END AS std,
0,0,0,
0,0,0,
0,0,0,
0,0,0,
0,0,0 from
(select a.cinvcode 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,-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
left join Inventory c WITH (nolock) on a.cInvCode=c.cInvCode
left join ComputationUnit LL WITH (nolock) on c.cComUnitCode=LL.cComunitCode
2021-05-28 09:23:02 +08:00
and a.cInvCode not in (select cInvCode from tempdb..tablepzck20210526)
2021-05-26 17:05:28 +08:00
2021-05-28 09:23:02 +08:00
insert into tempdb..tablepzck20210526
2021-05-26 17:05:28 +08:00
select a.cInvCode,c.cInvName,c.cInvStd,LL.cComUnitName ,
CASE
2021-05-28 09:23:02 +08:00
WHEN c.bPurchase = 1 AND c.bProxyForeign = 1 and c.bself = 1 THEN '外购,委外,自制'
WHEN c.bPurchase = 1 AND c.bProxyForeign = 1 and c.bself <>1 THEN '外购,委外'
WHEN c.bPurchase = 1 AND c.bProxyForeign <> 1 and c.bself <> 1 THEN '外购'
WHEN c.bPurchase = 1 AND c.bProxyForeign <> 1 and c.bself = 1 THEN '外购,自制'
WHEN c.bPurchase <> 1 AND c.bProxyForeign <> 1 and c.bself = 1 THEN '自制'
WHEN c.bPurchase <> 1 AND c.bProxyForeign = 1 and c.bself = 1 THEN '委外,自制'
WHEN c.bPurchase <> 1 AND c.bProxyForeign = 1 and c.bself <> 1 THEN '委外'
2021-05-26 17:05:28 +08:00
ELSE '其它'
END AS std,
0,0,0,
0,0,0,
0,0,0,
0,0,0,
0,0,0 from
(select a.cinvcode from rdrecords09 a WITH (nolock) left join rdrecord09 b WITH (nolock) on a.id=b.id
2021-04-29 19:56:30 +08:00
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)
2021-05-26 17:05:28 +08:00
group by a.cinvcode) a
left join Inventory c WITH (nolock) on a.cInvCode=c.cInvCode
left join ComputationUnit LL WITH (nolock) on c.cComUnitCode=LL.cComunitCode
2021-05-28 09:23:02 +08:00
and a.cInvCode not in (select cInvCode from tempdb..tablepzck20210526)
2021-05-26 17:05:28 +08:00
2021-05-28 09:23:02 +08:00
update a set a.iQuantity00=a.iQuantity00+isnull(a0.iQuantity,0) from tempdb..tablepzck20210526 a inner join
2021-05-26 17:05:28 +08:00
(select a.cinvcode, sum(a.iQuantity) as 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)
group by a.cinvcode
) a0 on isnull(a.cInvCode,'') =isnull(a0.cInvCode,'')
2021-04-29 19:56:30 +08:00
2021-05-28 09:23:02 +08:00
update a set a.iQuantity00=a.iQuantity00+isnull(a0.iQuantity,0) from tempdb..tablepzck20210526 a inner join
2021-05-26 17:05:28 +08:00
(select a.cinvcode, sum(a.iQuantity) as iQuantity from rdrecords32 a WITH (nolock) left join rdrecord32 b WITH (nolock) on a.id=b.id
2021-04-29 19:56:30 +08:00
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
2021-05-26 17:05:28 +08:00
) a0 on isnull(a.cInvCode,'') =isnull(a0.cInvCode,'')
2021-05-28 09:23:02 +08:00
update a set a.iQuantity00=a.iQuantity00+isnull(a0.iQuantity,0) from tempdb..tablepzck20210526 a inner join
2021-05-26 17:05:28 +08:00
(select a.cinvcode, sum(a.iQuantity) as iQuantity from rdrecords09 a WITH (nolock) left join rdrecord09 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)
group by a.cinvcode
) a0 on isnull(a.cInvCode,'') =isnull(a0.cInvCode,'')
2021-05-28 09:23:02 +08:00
update a set a.iQuantity01=a.iQuantity01+isnull(a1.iQuantity,0) from tempdb..tablepzck20210526 a inner join
2021-05-26 17:05:28 +08:00
(select a.cinvcode, sum(a.iQuantity) as 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(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 isnull(a.cInvCode,'') =isnull(a1.cInvCode,'')
2021-05-28 09:23:02 +08:00
update a set a.iQuantity01=a.iQuantity01+isnull(a1.iQuantity,0) from tempdb..tablepzck20210526 a inner join
2021-05-26 17:05:28 +08:00
(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
) a1 on isnull(a.cInvCode,'') =isnull(a1.cInvCode,'')
2021-05-28 09:23:02 +08:00
update a set a.iQuantity01=a.iQuantity01+isnull(a1.iQuantity,0) from tempdb..tablepzck20210526 a inner join
2021-05-26 17:05:28 +08:00
(select a.cinvcode, sum(a.iQuantity) as iQuantity from rdrecords09 a WITH (nolock) left join rdrecord09 b WITH (nolock) on a.id=b.id
2021-04-29 19:56:30 +08:00
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
2021-05-26 17:05:28 +08:00
) a1 on isnull(a.cInvCode,'') =isnull(a1.cInvCode,'')
2021-05-28 09:23:02 +08:00
update a set a.iQuantity02=a.iQuantity02+isnull(a2.iQuantity,0) from tempdb..tablepzck20210526 a inner join
2021-05-26 17:05:28 +08:00
(select a.cinvcode, sum(a.iQuantity) as 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(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
) a2 on isnull(a.cInvCode,'') =isnull(a2.cInvCode,'')
2021-05-28 09:23:02 +08:00
update a set a.iQuantity02=a.iQuantity02+isnull(a2.iQuantity,0) from tempdb..tablepzck20210526 a inner join
2021-05-26 17:05:28 +08:00
(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,-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
) a2 on isnull(a.cInvCode,'') =isnull(a2.cInvCode,'')
2021-05-28 09:23:02 +08:00
update a set a.iQuantity02=a.iQuantity02+isnull(a2.iQuantity,0) from tempdb..tablepzck20210526 a inner join
2021-05-26 17:05:28 +08:00
(select a.cinvcode, sum(a.iQuantity) as iQuantity from rdrecords09 a WITH (nolock) left join rdrecord09 b WITH (nolock) 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
) a2 on isnull(a.cInvCode,'') =isnull(a2.cInvCode,'')
2021-05-28 09:23:02 +08:00
update a set a.iQuantity03=a.iQuantity03+isnull(a3.iQuantity,0) from tempdb..tablepzck20210526 a inner join
2021-05-26 17:05:28 +08:00
(select a.cinvcode, sum(a.iQuantity) as iQuantity from rdrecords11 a WITH (nolock) left join rdrecord11 b WITH (nolock) on a.id=b.id
2021-04-29 19:56:30 +08:00
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
2021-05-21 09:32:30 +08:00
) a3 on a.cInvCode =a3.cInvCode
2021-05-26 17:05:28 +08:00
2021-05-28 09:23:02 +08:00
update a set a.iQuantity03=a.iQuantity03+isnull(a3.iQuantity,0) from tempdb..tablepzck20210526 a inner join
2021-05-26 17:05:28 +08:00
(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,-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
) a3 on a.cInvCode =a3.cInvCode
2021-05-28 09:23:02 +08:00
update a set a.iQuantity03=a.iQuantity03+isnull(a3.iQuantity,0) from tempdb..tablepzck20210526 a inner join
2021-05-26 17:05:28 +08:00
(select a.cinvcode, sum(a.iQuantity) as iQuantity from rdrecords09 a WITH (nolock) left join rdrecord09 b WITH (nolock) 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
) a3 on a.cInvCode =a3.cInvCode
2021-05-28 09:23:02 +08:00
update a set a.iQuantity04=a.iQuantity04+isnull(a4.iQuantity,0) from tempdb..tablepzck20210526 a inner join
2021-05-26 17:05:28 +08:00
(select left(convert(varchar,dateadd(month,-4,getdate()),112),6) as month1 , a.cinvcode, sum(a.iQuantity) as 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(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)
2021-04-29 19:56:30 +08:00
group by a.cinvcode
2021-05-26 17:05:28 +08:00
) a4 on a.cInvCode =a4.cInvCode
2021-05-28 09:23:02 +08:00
update a set a.iQuantity04=a.iQuantity04+isnull(a4.iQuantity,0) from tempdb..tablepzck20210526 a inner join
2021-05-26 17:05:28 +08:00
(select a.cinvcode, sum(a.iQuantity) as iQuantity from rdrecords32 a WITH (nolock) left join rdrecord32 b WITH (nolock) on a.id=b.id
2021-04-29 19:56:30 +08:00
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
2021-05-26 17:05:28 +08:00
2021-05-28 09:23:02 +08:00
update a set a.iQuantity04=a.iQuantity04+isnull(a4.iQuantity,0) from tempdb..tablepzck20210526 a inner join
2021-05-26 17:05:28 +08:00
(select a.cinvcode, sum(a.iQuantity) as iQuantity from rdrecords09 a WITH (nolock) left join rdrecord09 b WITH (nolock) 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
2021-05-28 09:23:02 +08:00
update a set a.iQuantity05=a.iQuantity05+isnull(a5.iQuantity,0) from tempdb..tablepzck20210526 a inner join
2021-05-26 17:05:28 +08:00
(select a.cinvcode, sum(a.iQuantity) as iQuantity from rdrecords11 a WITH (nolock) left join rdrecord11 b WITH (nolock) on a.id=b.id
2021-04-29 19:56:30 +08:00
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
2021-05-26 17:05:28 +08:00
2021-05-28 09:23:02 +08:00
update a set a.iQuantity05=a.iQuantity05+isnull(a5.iQuantity,0) from tempdb..tablepzck20210526 a inner join
2021-05-26 17:05:28 +08:00
(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,-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
2021-05-28 09:23:02 +08:00
update a set a.iQuantity05=a.iQuantity05+isnull(a5.iQuantity,0) from tempdb..tablepzck20210526 a inner join
2021-05-26 17:05:28 +08:00
(select a.cinvcode, sum(a.iQuantity) as iQuantity from rdrecords09 a WITH (nolock) left join rdrecord09 b WITH (nolock) 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
2021-05-28 09:23:02 +08:00
update a set a.wqty=a.wqty+isnull(mas.wqty,0) from tempdb..tablepzck20210526 a inner join
2021-05-26 17:05:28 +08:00
(SELECT ma.invcode, SUM(isnull(ma.qty, 0) - isnull(issqty, 0)) wqty
2021-05-06 11:35:41 +08:00
FROM mom_moallocate ma WITH (nolock) INNER JOIN
mom_orderdetail md WITH (nolock) ON ma.MoDId = md.MoDId
2021-04-29 19:56:30 +08:00
WHERE md.Status <> 4 AND ma.Qty - ISNULL(ma.IssQty, 0) > 0
2021-05-26 17:05:28 +08:00
GROUP BY ma.InvCode) mas ON a.cInvCode = mas.InvCode
2021-05-28 09:23:02 +08:00
update a set a.issqty=a.issqty+isnull(misss.issqty,0) from tempdb..tablepzck20210526 a inner join
2021-05-26 17:05:28 +08:00
(SELECT ma.invcode, SUM( isnull(issqty, 0)) issqty
2021-05-06 11:35:41 +08:00
FROM mom_moallocate ma WITH (nolock) INNER JOIN
mom_orderdetail md WITH (nolock) ON ma.MoDId = md.MoDId
2021-04-29 19:56:30 +08:00
WHERE md.Status <> 4
2021-05-26 17:05:28 +08:00
GROUP BY ma.InvCode) misss ON a.cInvCode = misss.InvCode
2021-04-29 19:56:30 +08:00
2021-05-28 09:23:02 +08:00
update a set a.issqty=a.issqty+isnull(misss.issqty,0) from tempdb..tablepzck20210526 a inner join
2021-05-26 17:05:28 +08:00
(SELECT ma.invcode, SUM( isnull(issqty, 0)) issqty
FROM mom_moallocate ma WITH (nolock) INNER JOIN
mom_orderdetail md WITH (nolock) ON ma.MoDId = md.MoDId
WHERE md.Status <> 4
GROUP BY ma.InvCode) misss ON a.cInvCode = misss.InvCode
2021-05-28 09:23:02 +08:00
update a set a.dqty=a.dqty+isnull(ds.qty,0),a.cqty=a.cqty+isnull(cs.qty,0) from tempdb..tablepzck20210526 a inner join
2021-05-26 17:05:28 +08:00
(SELECT cinvcode, SUM(iquantity) qty
2021-05-06 11:35:41 +08:00
FROM currentstock WITH (nolock)
2021-05-26 17:05:28 +08:00
GROUP BY cInvCode) cs ON a.cInvCode = cs.cInvCode
2021-04-29 19:56:30 +08:00
LEFT JOIN
(SELECT cinvcode, SUM(iquantity) qty
2021-08-16 15:24:37 +08:00
FROM InvPositionSum WITH (nolock) where cPosCode not in ('00701','00801','09001') and cWhCode not in (4,5)
2021-05-26 17:05:28 +08:00
GROUP BY cInvCode) ds ON a.cInvCode = ds.cInvCode
update a set a.momqty=a.momqty+isnull(MX.MQTY,0)
2021-05-28 09:23:02 +08:00
from tempdb..tablepzck20210526 a inner join
2021-05-26 17:05:28 +08:00
(SELECT MD.INVCODE, SUM(MD.QTY - ISNULL(MD.QUALIFIEDINQTY, 0)) AS MQTY
2021-05-06 11:35:41 +08:00
FROM mom_orderdetail MD WITH (nolock)
2021-05-26 17:05:28 +08:00
GROUP BY MD.INVCODE) MX ON a.cInvCode = MX.InvCode
update a set a.rqty=a.rqty+isnull(prd.rqty,0)
2021-05-28 09:23:02 +08:00
from tempdb..tablepzck20210526 a inner join
2021-04-29 19:56:30 +08:00
(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
2021-05-26 17:05:28 +08:00
GROUP BY cInvCode) prd ON a.cInvCode = prd.cInvCode
update a set a.rqty1=a.rqty1+isnull(OMM.RQTY1,0)
2021-05-28 09:23:02 +08:00
from tempdb..tablepzck20210526 a inner join
2021-04-29 19:56:30 +08:00
(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
2021-05-26 17:05:28 +08:00
GROUP BY cInvCode) OMM ON a.cInvCode = OMM.CINVCODE
update a set a.rqty3=a.rqty3+isnull(pu_App.RQTY3,0)
2021-05-28 09:23:02 +08:00
from tempdb..tablepzck20210526 a inner join
2021-04-29 19:56:30 +08:00
(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
2021-05-26 17:05:28 +08:00
GROUP BY cInvCode) pu_App ON a.cInvCode = pu_App.CINVCODE
2021-05-28 09:23:02 +08:00
update tempdb..tablepzck20210526 set q=isnull(wqty,0) - isnull(dqty, 0) - ISNULL(rqty, 0) - ISNULL(rqty1, 0)- ISNULL(rqty3, 0)- ISNULL(momqty, 0)
2021-05-26 17:05:28 +08:00
2021-05-28 09:23:02 +08:00
select *from tempdb..tablepzck20210526
2021-05-26 17:05:28 +08:00
2021-04-29 19:56:30 +08:00
";
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
{
2021-05-28 09:23:02 +08:00
where.Add(" cinvcode in @cinvcode");
2021-04-29 19:56:30 +08:00
}
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))
{
2021-05-28 09:23:02 +08:00
sql += " where " + aa;
2021-04-29 19:56:30 +08:00
}
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-05-04 14:43:24 +08:00
public IEnumerable<object> Inventorysocode(NX.ERP.Model.Request.SaleOrderRequest info1)
2021-04-29 19:56:30 +08:00
{
string sql = $@"
2021-05-18 14:52:39 +08:00
select j.cSTName,b.cSOCode,CONVERT(varchar(100),b.dDate, 23) as dDate ,a.iRowNo,f.cCusAbbName,a.cInvCode,a.cInvName,g.cInvStd,a.iQuantity, CONVERT(varchar(100),a.dPreDate, 23) as dPreDate , CONVERT(varchar(100),h.dDate, 23) as fhdDate ,isnull(c.fqty,0)fqty,isnull(d.cqty,0)cqty
2021-04-29 19:56:30 +08:00
,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
2021-05-18 14:52:39 +08:00
2021-04-29 19:56:30 +08:00
";
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-05-04 14:43:24 +08:00
if (info1.SoCodes != null)
2021-04-29 19:56:30 +08:00
{
2021-05-04 14:43:24 +08:00
where.Add(" b.cSOCode in @cSOCode ");
}
if (info1.BeginDate != null && info1.EndDate != null)
{
where.Add(" b.dDate between @beginDate and @endDate ");
2021-04-29 19:56:30 +08:00
}
2021-05-04 14:43:24 +08:00
if (!info1.byFinish)
{
where.Add(" h.dDate is null ");
}
2021-04-29 19:56:30 +08:00
var aa = string.Join(" and ", where.ToArray());
if (!string.IsNullOrEmpty(aa))
{
2021-05-28 09:23:02 +08:00
sql += " where " + aa;
2021-04-29 19:56:30 +08:00
}
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-05-04 14:43:24 +08:00
return conn.Query<object>(sql, new { cinvcode = info1.InvCodes, cInvStd = $"%{info1.InvStd}%", cSOCode = info1.SoCodes, info1.BeginDate, info1.EndDate });
2021-04-29 19:56:30 +08:00
}
}
2021-10-19 15:42:24 +08:00
2021-10-20 17:28:09 +08:00
public IEnumerable<object> InventorySale(NX.ERP.Model.Request.SaleinvRequest info1)
2021-10-19 15:42:24 +08:00
{
string sql = $@"
2021-10-20 17:28:09 +08:00
select *from (
2021-10-19 15:42:24 +08:00
select f.cCusAbbName,CONVERT(varchar(100),b.dDate, 23) as dDate ,b.cSOCode,a.cInvCode,a.cInvName,g.cInvStd, a.iQuantity - isnull(d.cqty,0) as wfiQuantity
,
2021-10-20 17:28:09 +08:00
isnull(cs.qty,0) as xcl,
b.cVerifier
2021-10-19 15:42:24 +08:00
,
isnull(
(SELECT isnull(SUM(iquantity),0) qty
FROM currentstock WITH (nolock) where cInvCode=a.cInvCode
GROUP BY cInvCode
),0)-( select sum(aa.iQuantity - isnull(dd.cqty,0)) as swfiQuantity from SO_SODetails aa WITH (nolock) LEFT JOIN
SO_SOMain bb WITH (nolock) on aa.ID=bb.id left join
(SELECT ipesodid, sum(iQuantity) AS cqty
FROM rdrecords32 WITH (nolock)
GROUP BY ipesodid) dd on isnull(dd.ipesodid,'')=isnull(aa.iSOsID ,'')
where aa.cInvCode=a.cInvCode and bb.cVerifier is not null and isnull(CONVERT(varchar(100),aa.dPreDate, 23),'1900-01-01')<=isnull(CONVERT(varchar(100),a.dPreDate, 23),'1900-01-01') and (aa.iQuantity - isnull(dd.cqty,0))>0
group by aa.cInvCode
) as kcyl
,
CONVERT(varchar(100),a.dPreDate, 23) as dPreDate , a.cMemo,
CASE
WHEN DATEDIFF(day,a.dPreDate,GETDATE()) > -15 AND DATEDIFF(day,a.dPreDate,GETDATE()) < 0 THEN '15天内发货'
WHEN DATEDIFF(day,a.dPreDate,GETDATE()) <= -15 THEN '15天以上发货'
WHEN DATEDIFF(day,a.dPreDate,GETDATE()) >=0 THEN '超期'
END AS datewaring,
DATEDIFF(day,a.dPreDate,GETDATE()) as jandate
from SO_SODetails a WITH (nolock) left join SO_SOMain b WITH (nolock) on a.ID=b.id
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 Customer f WITH (nolock) on b.cCusCode=f.cCusCode
2021-10-20 17:28:09 +08:00
left join Inventory g WITH (nolock) on g.cInvCode=a.cInvCode ) mm
2021-10-19 15:42:24 +08:00
";
List<string> where = new List<string>();
2021-10-20 17:28:09 +08:00
// where.Add(" a.iQuantity - isnull(d.cqty,0) >0 and b.cVerifier is not null ");
2021-10-19 15:42:24 +08:00
2021-10-20 17:28:09 +08:00
where.Add(" mm.wfiQuantity >0 and mm.cVerifier is not null ");
if (!string.IsNullOrEmpty(info1.cCusAbbName))
2021-10-19 15:42:24 +08:00
{
2021-10-20 17:28:09 +08:00
where.Add(" mm.cCusAbbName like @cCusAbbName ");
2021-10-19 15:42:24 +08:00
}
2021-10-20 17:28:09 +08:00
if (!string.IsNullOrEmpty(info1.dDate))
2021-10-19 15:42:24 +08:00
{
2021-10-20 17:28:09 +08:00
where.Add(" mm.dDate = @dDate ");
2021-10-19 15:42:24 +08:00
}
2021-10-20 17:28:09 +08:00
if (!string.IsNullOrEmpty(info1.cSOCode))
2021-10-19 15:42:24 +08:00
{
2021-10-20 17:28:09 +08:00
where.Add(" mm.cSOCode = @cSOCode ");
2021-10-19 15:42:24 +08:00
}
2021-10-20 17:28:09 +08:00
if (!string.IsNullOrEmpty(info1.cInvCode))
2021-10-19 15:42:24 +08:00
{
2021-10-20 17:28:09 +08:00
where.Add(" mm.cInvCode like @cInvCode ");
}
if (!string.IsNullOrEmpty(info1.cInvName))
{
where.Add(" mm.cInvName like @cInvName ");
}
2021-10-19 15:42:24 +08:00
2021-10-20 17:28:09 +08:00
if (!string.IsNullOrEmpty(info1.cInvStd))
{
where.Add(" mm.cInvStd like @cInvStd ");
}
if (!string.IsNullOrEmpty(info1.cMemo))
{
where.Add(" mm.cMemo like @cMemo ");
}
if (!string.IsNullOrEmpty(info1.dPreDate))
{
where.Add(" mm.dPreDate = @dPreDate ");
}
if (!string.IsNullOrEmpty(info1.wfiQuantity))
{
where.Add(" mm.wfiQuantity = @wfiQuantity ");
}
if (!string.IsNullOrEmpty(info1.kcyl))
{
where.Add(" mm.kcyl = @kcyl ");
}
if (!string.IsNullOrEmpty(info1.jandate))
{
where.Add(" mm.jandate = @jandate ");
2021-10-19 15:42:24 +08:00
}
2021-10-20 17:28:09 +08:00
if (!string.IsNullOrEmpty(info1.kcyl2))
{
if (info1.kcyl2 == "1")
{
where.Add(" mm.kcyl <= 0 ");
}
else if (info1.kcyl2 == "2")
{
where.Add(" mm.kcyl > 0 ");
}
}
if (!string.IsNullOrEmpty(info1.datewaring))
{
if (info1.datewaring == "1")
{
where.Add(" (mm.jandate > -15 AND mm.jandate < 0) ");
}
else if (info1.datewaring == "2")
{
where.Add("(mm.jandate <= -15) ");
}
else if (info1.datewaring == "3")
{
where.Add("(mm.jandate >= 0) ");
}
}
/*
if (info1.InvCodes != null)
{
where.Add(" mm.cinvcode in @cinvcode");
}
if (!string.IsNullOrEmpty(info1.InvStd))
{
where.Add(" mm.cInvStd like @cInvStd ");
}
if (info1.SoCodes != null)
{
where.Add(" mm.cSOCode in @SoCodes ");
}
*/
2021-10-19 16:05:46 +08:00
if (info1.flag != null && info1.flag.ToList().Count>0)
2021-10-19 15:42:24 +08:00
{
List<string> str = new List<string>();
foreach (var item in info1.flag)
{
if (item == "1")
{
2021-10-20 17:28:09 +08:00
str.Add(" (mm.jandate > -15 AND mm.jandate < 0) ");
2021-10-19 15:42:24 +08:00
}
else if (item == "2")
{
2021-10-20 17:28:09 +08:00
str.Add(" (mm.jandate <= -15) ");
2021-10-19 15:42:24 +08:00
}
else
{
2021-10-20 17:28:09 +08:00
str.Add(" (mm.jandate >= 0) ");
2021-10-19 15:42:24 +08:00
}
}
var strs = string.Join(" or ", str.ToArray());
2021-10-19 16:05:46 +08:00
2021-10-19 15:42:24 +08:00
strs = " ( " + strs + " ) ";
where.Add(strs);
}
var aa = string.Join(" and ", where.ToArray());
if (!string.IsNullOrEmpty(aa))
{
sql += " where " + aa;
}
using (var conn = NX.ERP.U8.U8LoginContext.Instance.Connection)
{
2021-10-20 17:28:09 +08:00
return conn.Query<object>(sql, new { cCusAbbName = $"%{info1.cCusAbbName}%", dDate = info1.dDate, dPreDate = info1.dPreDate, cSOCode = info1.cSOCode, cInvCode = $"%{info1.cInvCode}%" , cInvName = $"%{info1.cInvName}%" , cInvStd = $"%{info1.cInvStd}%" , cMemo = $"%{info1.cMemo}%", SoCodes = info1.SoCodes, info1.jandate, info1.wfiQuantity, info1.kcyl, });
2021-10-19 15:42:24 +08:00
}
}
2021-05-18 15:19:51 +08:00
public IEnumerable<object> InventoryPo(NX.ERP.Model.Request.PoOrderRequest info1)
{
string sql = $@"
2021-05-26 17:05:28 +08:00
Select cpoid,zpurpoheader.cmaker,CONVERT(varchar(100),dpodate, 23) as dpodate,zpurpoheader.cvenabbname,zpurpotail.cinvcode,zpurpotail.cinvname,zpurpotail.cinvstd,zpurpotail.cinvm_unit,zpurpotail.ireceivedqty,
zpurpotail.iquantity,prd.rqty,prd2.rqty as rqty2 ,CONVERT(varchar(100), zpurpotail.darrivedate, 23) as darrivedate,cupsocode, CONVERT(varchar(100), d.ddate, 23) as ddate, CONVERT(varchar(100), c.drequirdate, 23) as drequirdate,
2021-05-21 09:32:30 +08:00
zpurpotail.cbcloser,zpurpoheader.ccloser
2021-05-18 15:19:51 +08:00
From zpurpoheader with(nolock) inner join zpurpotail with(nolock) on zpurpoheader.poid=zpurpotail.poid
left join pu_appbody c with(nolock) on zpurpotail.iAppIds =c.autoid
left join pu_apphead d with(nolock) on d.id =c.id
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 zpurpotail.cinvcode = prd.CINVCODE
2021-05-26 17:05:28 +08:00
LEFT JOIN
(SELECT ID, cinvcode, SUM(rqty) AS rqty
FROM (SELECT PDS.ID,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 ID,cInvCode) prd2 ON zpurpotail.cinvcode = prd2.CINVCODE and prd2.ID =zpurpotail.id
2021-05-18 15:19:51 +08:00
";
List<string> where = new List<string>();
if (info1.InvCodes != null)
{
where.Add(" zpurpotail.cinvcode in @cinvcode");
}
if (!string.IsNullOrEmpty(info1.InvStd))
{
where.Add(" zpurpotail.cinvstd like @cInvStd ");
}
if (info1.PoCodes != null)
{
where.Add(" cpoid in @PoCodes ");
}
if (info1.AppCodes != null)
{
where.Add(" cupsocode in @AppCodes ");
}
if (info1.BeginDate != null && info1.EndDate != null)
{
where.Add(" zpurpoheader.dPODate between @beginDate and @endDate ");
}
if (info1.BeginDate2 != null && info1.EndDate2 != null)
{
where.Add(" d.dDate between @beginDate2 and @endDate2 ");
}
2021-05-21 09:32:30 +08:00
if (!info1.byFinish)
{
2021-05-25 00:40:12 +08:00
where.Add(" isnull(zpurpotail.cbcloser,'') ='' and zpurpotail.ireceivedqty <> zpurpotail.iquantity ");
2021-05-21 09:32:30 +08:00
}
2021-05-18 15:19:51 +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 { cinvcode = info1.InvCodes, cInvStd = $"%{info1.InvStd}%", info1.PoCodes, info1.AppCodes, info1.BeginDate, info1.EndDate, info1.BeginDate2, info1.EndDate2 });
}
}
2021-05-13 14:29:58 +08:00
public IEnumerable<object> Inventorybu(NX.ERP.Model.Request.Inventorybu info1)
2021-05-12 17:01:59 +08:00
{
using (var conn = NX.ERP.U8.U8LoginContext.Instance.Connection)
{
DynamicParameters sp = new DynamicParameters(info1);
2021-05-13 14:29:58 +08:00
string sql;
if (info1.outycl == true && info1.outbcp == true)
{
sql = $@"Usp_BO_ExpandByParent_BU_20210513_4 ";
}
else if (info1.outycl == true && info1.outbcp == false)
{
sql = $@"Usp_BO_ExpandByParent_BU_20210513_1 ";
}
else if (info1.outycl == false && info1.outbcp == true)
{
sql = $@"Usp_BO_ExpandByParent_BU_20210513_3 ";
}
else
{
sql = $@" Usp_BO_ExpandByParent_BU_20210513 ";
}
//var sql = $@"Usp_BO_ExpandByParent_BU_20210208 ";
2021-05-18 14:52:39 +08:00
if (info1.inumsc != null)
2021-05-12 17:01:59 +08:00
{
2021-05-18 14:52:39 +08:00
foreach (var item in info1.inumsc)
{
2021-05-12 17:01:59 +08:00
2021-05-18 14:52:39 +08:00
sql = sql + "'" + item + "'" + ",";
}
sql = sql.Substring(0, sql.Length - 1);
}
else {
sql = "";
}
try { return conn.Query<object>(sql, new { inumsc = info1.inumsc }); }
catch { return null; }
2021-05-12 17:01:59 +08:00
}
}
2021-04-29 13:55:18 +08:00
}
}