修正到货单返回慢的错误

This commit is contained in:
gongxh
2021-06-04 12:22:02 +08:00
parent 0644817c17
commit 43b9e3473a

View File

@@ -7,40 +7,79 @@ namespace NX.ERP.U8.Purchase
{ {
public class ArrivalDAL public class ArrivalDAL
{ {
public IEnumerable<Model.Purchase.Arrival> GetList(string where , object param = null) public IEnumerable<Model.Purchase.Arrival> GetList(string where, object param = null)
{ {
using (var conn = U8LoginContext.Instance.Connection) using (var conn = U8LoginContext.Instance.Connection)
{ {
string strSQL = @"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,a.dDate as ArrivalDate,A.cVenCode AS SupplierCode, // string strSQL = @"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,a.dDate as ArrivalDate,A.cVenCode AS SupplierCode,
B.Autoid as id,b.ID as ArrivalID, // B.Autoid as id,b.ID as ArrivalID,
b.cInvCode AS MaterialCode, // b.cInvCode AS MaterialCode,
b.cBatch AS BatchNo, // b.cBatch AS BatchNo,
b.fvalidinquan as RealQuantity, // 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.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, // 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 //Pos.cPosName
FROM pu_ArrBody b inner join pu_ArrHead a on a.id=b.id // FROM pu_ArrBody b inner join pu_ArrHead a on a.id=b.id
inner join (select cinvcode as cinvcode1,iId from inventory) inventory on b.cinvcode=inventory.cinvcode1 // inner join (select cinvcode as cinvcode1,iId from inventory) inventory on b.cinvcode=inventory.cinvcode1
Left Join PO_Podetails C WITH (NOLOCK) ON B.iPOsID = C.ID , // Left Join PO_Podetails C WITH (NOLOCK) ON B.iPOsID = C.ID ,
(SELECT cinvcode, //(SELECT cinvcode,
STUFF( //STUFF(
( // (
SELECT ','+ cPosName FROM ( select b.cPosName,a.cInvCode,a.iQuantity from InvPositionSum a WITH (NOLOCK) left join Position b WITH (NOLOCK) on a.cPosCode=b.cPosCode // SELECT ','+ cPosName FROM ( select b.cPosName,a.cInvCode,a.iQuantity from InvPositionSum a WITH (NOLOCK) left join Position b WITH (NOLOCK) on a.cPosCode=b.cPosCode
where a.iQuantity <>0) a WHERE b.cinvcode = a.cinvcode order by a.iQuantity desc FOR XML PATH('') // where a.iQuantity <>0) a WHERE b.cinvcode = a.cinvcode order by a.iQuantity desc FOR XML PATH('')
),1 ,1, '') cPosName // ),1 ,1, '') cPosName
//FROM InvPositionSum b
//GROUP BY cinvcode
//) Pos -- on isnull (b.cInvCode,'')=isnull(Pos.cInvCode,'')
// 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 isnull(a.cverifier,'')<>''
// 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";
string strSQL = @"select a.ID as ArrivalId,A.cCode as ArrivalCode,c.cpersonname,a.cPersonCode,a.cBusType as busType,
a.cPTCode as PTCode,a.iTaxRate as TaxRate,a.iexchrate as Exchrate,a.cexch_name as ExchName,
a.cVenCode as VenCode,a.dDate as ArrivalDate,A.cVenCode AS SupplierCode,
B.Autoid as id,b.ID as ArrivalID,b.cInvCode AS MaterialCode, b.cBatch AS BatchNo, b.fvalidinquan as RealQuantity,
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,b.iNum,
b.cunitid,d.ccomunitcode AS UnitCode,CASE WHEN isnull(d.igrouptype, 0) = 0 THEN NULL ELSE unit2.ccomunitname END AS cinva_unit,
Unit1.cComUnitName AS cinvm_unit,d.ccomunitcode,
CASE WHEN isNull(b.cbcloser, '') = '' THEN 0 WHEN isNull(b.cbcloser, '')
<> '' THEN 1 ELSE 2 END AS vouchstate, ISNULL(b.iQuantity, 0)
- ISNULL(b.fRefuseQuantity, 0) - ISNULL(b.fValidInQuan, 0)
- ISNULL(b.fInValidInQuan, 0) AS fininquantity, CASE WHEN isnull(d.igrouptype, 0)
= 0 THEN NULL WHEN isnull(d.igrouptype, 0) = 1 THEN (isnull(b.iquantity, 0)
- isnull(frefusequantity, 0) - isnull(fvalidinquan, 0) - isnull(finvalidinquan, 0))
/ unit2.ichangrate WHEN isnull(d.igrouptype, 0) = 2 THEN (isnull(b.inum, 0) - isnull(frefusenum,
0) - isnull(fvalidinnum, 0) - isnull(finvalidinnum, 0)) END AS fininnum, (CASE WHEN isnull(b.dPDate, '')
= N'' AND isnull(b.imassDate, 0) = 0 THEN CONVERT(nvarchar(7), b.dvdate, 121)
ELSE CONVERT(nvarchar(7), dateadd(month, - 1, b.dvdate), 121) END) AS dValidateDate,
(CASE WHEN ((isnull(b.inum, 0) - isnull(b.finspectnum, 0)) = 0 OR
isnull(b.inum, 0) IS NULL) AND isnull(d.igrouptype, 0)
<> 1 THEN 0 ELSE (CASE WHEN isnull(d.igrouptype, 0)
= 1 THEN unit2.ichangrate ELSE ((isnull(b.iquantity, 0) - isnull(b.finspectquantity, 0))
/ (isnull(b.inum, 0) - isnull(b.finspectnum, 0))) END) END) AS inspecexchrate,
e.POID as Poid,Pos.cPosName,
CASE WHEN isnull(f.bflowprocess, 0) = 1 THEN isnull(f.bstoragearrivalorder, 1) ELSE 1 END AS bstoragearrivalorder,
Pos.cPosName
from PU_ArrivalVouch a
left join PU_ArrivalVouchs b on a.ID=b.ID
left join Person c ON a.cPersonCode = c.cPersonCode
LEFT JOIN Inventory d ON b.cInvCode =d.cInvCode
LEFT JOIN dbo.ComputationUnit AS Unit2 ON B.cUnitID = Unit2.cComunitCode
LEFT JOIN dbo.ComputationUnit AS Unit1 ON d.cComUnitCode = Unit1.cComunitCode
Left Join PO_Podetails e ON B.iPOsID = e.ID
LEFT JOIN dbo.PUBizFlow f ON f.iFlowID = a.iflowid
left join (SELECT cinvcode, STUFF(( SELECT ','+ cPosName FROM ( select b.cPosName,a.cInvCode,a.iQuantity from InvPositionSum a left join Position b on a.cPosCode=b.cPosCode
where a.iQuantity <>0) a WHERE b.cinvcode = a.cinvcode order by a.iQuantity desc FOR XML PATH('')),1 ,1, '') cPosName
FROM InvPositionSum b FROM InvPositionSum b
GROUP BY cinvcode GROUP BY cinvcode
) Pos -- on isnull (b.cInvCode,'')=isnull(Pos.cInvCode,'') ) Pos on b.cInvCode=Pos.cInvCode
Where ( (1>0) AND (1>0) ) AND ( 1>0 ) and (isnull(cbustype,'')<>'委外加工') and isnull (b.cInvCode,'')=isnull(Pos.cInvCode,'') where
And (1=1) and isnull(b.cbcloser,N'')=N'' And isnull(a.cverifier,'')<>'' (isnull(cbustype,'')<>'委外加工') and isnull (b.cInvCode,'')=isnull(Pos.cInvCode,'')
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.cbcloser,'')='' And isnull(a.cverifier,'')<>''
and isnull(b.inum,0)-isnull(b.frefusenum,0)>isnull(b.fvalidinnum,0))) and isnull(a.bStorageArrivalOrder,1)=1 and 1=1 And a.iBillType ='0' and isnull(b.bGsp,'')='0' and (isnull(b.iQuantity,0)-isnull(b.fRefuseQuantity,0)>isnull(b.fValidInQuan,0) or (d.igrouptype=2
and isnull(b.inum,0)-isnull(b.frefusenum,0)>isnull(b.fvalidinnum,0))) and isnull(bStorageArrivalOrder,1)=1 ";
";
if (!string.IsNullOrEmpty(where)) if (!string.IsNullOrEmpty(where))
{ {
strSQL += " and " + where; strSQL += " and " + where;
@@ -88,7 +127,7 @@ namespace NX.ERP.U8.Purchase
{ {
List<string> where = new List<string>(); List<string> where = new List<string>();
where.Add("a.id=@Id"); where.Add("a.id=@Id");
return this.GetList(where, new { id }).FirstOrDefault(); return this.GetList(where, new { id }).FirstOrDefault();
@@ -101,7 +140,7 @@ namespace NX.ERP.U8.Purchase
List<string> where = new List<string>(); List<string> where = new List<string>();
//处理- //处理-
if (!string.IsNullOrEmpty(arrival.cInvCode) ) if (!string.IsNullOrEmpty(arrival.cInvCode))
{ {
where.Add(" b.cinvcode = @cinvcode"); where.Add(" b.cinvcode = @cinvcode");
} }
@@ -114,7 +153,7 @@ namespace NX.ERP.U8.Purchase
where.Add(" a.cCode = @cCode"); where.Add(" a.cCode = @cCode");
} }
return this.GetList(where, new { cCodelist = arrival.ArrivalNolist, cinvcode= arrival.cInvCode, cCode = arrival.ArrivalNo }); return this.GetList(where, new { cCodelist = arrival.ArrivalNolist, cinvcode = arrival.cInvCode, cCode = arrival.ArrivalNo });
} }
public IEnumerable<Model.Purchase.Arrival> GetListByLastId(int Id) public IEnumerable<Model.Purchase.Arrival> GetListByLastId(int Id)