Files
U8-Import/NX.ERP.U8/Pmc/WarehouseQuery.cs
杰 朱 f4b34807a9 1
2022-03-22 19:55:46 +08:00

141 lines
6.0 KiB
C#

using NX.ERP.U8.Purchase;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using Dapper;
namespace NX.ERP.U8.Finance
{
public class WarehouseQuery
{
/// <summary>
///
/// </summary>
/// <param name="strWhere"></param>
/// <param name="param"></param>
/// <returns></returns>
public IEnumerable<object> ArrivalGet(NX.ERP.Model.Request.Arrival arrival)
{
string sql = @"IF EXISTS (SELECT NAME FROM tempdb..SYSOBJECTS WHERE NAME ='tablearrive20210603' AND Xtype='U') DROP Table tempdb..tablearrive20210603
create table tempdb..tablearrive20210603 (
cinvcode nvarchar(120),
cPosName nvarchar(2000),
)
CREATE INDEX IX_test ON tempdb..tablearrive20210603 (cinvcode)
insert into tempdb..tablearrive20210603
SELECT cinvcode,
STUFF(
(
SELECT ','+ cPosName FROM ( select b.cPosName,a.cInvCode,a.iQuantity from InvPositionSum a WITH (NOLOCK) , Position b WITH (NOLOCK)
where a.iQuantity <>0 and a.cPosCode=b.cPosCode ) a WHERE b.cinvcode = a.cinvcode order by a.iQuantity desc FOR XML PATH('')
),1 ,1, '') cPosName
FROM InvPositionSum b
GROUP BY cinvcode
select a.id AS ArrivalId,a.cCode as ArrivalCode,a.cpersoncode,a.cpersonname,A.cbustype AS busType,a.cptcode as PTCode,a.iTaxRate as TaxRate,a.iexchrate as Exchrate,cexch_name as ExchName,cVenCode as VenCode, CONVERT(varchar(100), a.dDate, 23) as ArrivalDate,A.cVenCode AS SupplierCode,
B.Autoid as id,b.ID as ArrivalID,
b.cInvCode AS MaterialCode,cinvname ,cinvstd,
b.cBatch AS BatchNo,
b.fvalidinquan as RealQuantity,
b.ccomunitcode AS UnitCode,b.ioricost as oricost,b.ioritaxcost as oritaxcost ,b.icost as cost,b.iorimoney as orimoney,b.ioritaxprice as oritaxprice,b.iorisum as orisum,b.isum as sum,
B.iQuantity as Quantity,b.iposid as PosId ,B.CORDERCODE as OrderCode,C.POID as Poid,b.iNum,b.ccomunitcode,b.cunitid,b.cinva_unit,b.cinvm_unit,b.inspecexchrate,
Pos.cPosName
FROM pu_ArrBody b left join tempdb..tablearrive20210603 Pos on isnull (b.cInvCode,'')=isnull(Pos.cInvCode,'') , pu_ArrHead a
, (select cinvcode as cinvcode1,iId from inventory WITH (NOLOCK) ) inventory
, PO_Podetails C WITH (NOLOCK)
Where ( (1>0) AND (1>0) ) AND ( 1>0 ) and (isnull(cbustype,'')<>'委外加工') -- and ( isnull (b.cInvCode,'')=isnull(Pos.cInvCode,''))
And (1=1) and isnull(b.cbcloser,N'')=N'' and a.id=b.id and b.cinvcode=inventory.cinvcode1 and B.iPOsID = C.ID
And a.iBillType =N'0' and isnull(b.bGsp,N'')=N'0' and (isnull(b.iQuantity,0)-isnull(b.fRefuseQuantity,0)>isnull(b.fValidInQuan,0) or (b.igrouptype=2
and isnull(b.inum,0)-isnull(b.frefusenum,0)>isnull(b.fvalidinnum,0))) and isnull(a.bStorageArrivalOrder,1)=1 and 1=1
";
List<string> where = new List<string>();
//处理-
if (!string.IsNullOrEmpty(arrival.cInvCode))
{
where.Add(" b.cinvcode = @cinvcode");
}
if (arrival.ArrivalNolist != null && arrival.ArrivalNolist.Count > 0)
{
where.Add(" a.cCode in @cCodelist");
}
if (!string.IsNullOrEmpty(arrival.ArrivalNo))
{
where.Add(" a.cCode = @cCode");
}
var aa = string.Join(" and ", where.ToArray());
if (!string.IsNullOrEmpty(aa))
{
sql += " and " + aa;
}
using (var conn = NX.ERP.U8.U8LoginContext.Instance.Connection)
{
return conn.Query<object>(sql, new { cCodelist = arrival.ArrivalNolist, cinvcode = arrival.cInvCode, cCode = arrival.ArrivalNo });
}
}
public IEnumerable<object> QmError()
{
string sql = @" select isnull(a.CINVCODE,'') as qminvcode,a.CINVNAME,isnull(b.cInvCode,'') as poinvcode,a.CREJECTCODE,d.cCode,f.cCode as rkcCode
from QM_QPERREJECTLIST a WITH (NOLOCK) left join PO_Podetails b WITH (NOLOCK) on a.IPUPODID=b.id
left join PU_ArrivalVouchs c WITH (NOLOCK) on a.id=c.irejectautoid
left join PU_ArrivalVouch d WITH (NOLOCK) on c.id=d.id
left join RdRecords01 e WITH (NOLOCK) on c.Autoid=e.iArrsId
left join RdRecord01 f WITH (NOLOCK) on e.id=f.id
where isnull(a.CINVCODE,'')<>isnull(b.cInvCode,'') and b.id is not null";
using (var conn = NX.ERP.U8.U8LoginContext.Instance.Connection)
{
return conn.Query<object>(sql, new {});
}
}
public IEnumerable<object> GetList(Model.Request.OtherStoreInOut storeIn)
{
string sql = @" select a.cInvCode,a.iQuantity,a.cPosition,b.cCode From rdrecords11 a left join rdrecord11 b on a.id=b.ID
where 1=1
";
List<string> where = new List<string>();
if (!string.IsNullOrEmpty(storeIn.Code))
{
where.Add(" b.cCode = @cCode");
}
var aa = string.Join(" and ", where.ToArray());
if (!string.IsNullOrEmpty(aa))
{
sql += " and " + aa;
}
using (var conn = NX.ERP.U8.U8LoginContext.Instance.Connection)
{
return conn.Query<object>(sql, new { cCode = storeIn.Code });
}
}
}
}