Files
U8-Import/NX.ERP.U8/Qmcheck/QmcheckDAL.cs

137 lines
15 KiB
C#

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Dapper;
namespace NX.ERP.U8.Qmcheck
{
public class QmcheckDAL
{
public IEnumerable<Model.Qmcheck.Qmcheckvoucher> GetList(string where, object param = null)
{
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,
// B.Autoid as id,b.ID as ArrivalID,
// b.cInvCode AS MaterialCode,
// 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 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
// Left Join PO_Podetails C WITH (NOLOCK) ON B.iPOsID = C.ID ,
//(SELECT cinvcode,
//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
// where a.iQuantity <>0) a WHERE b.cinvcode = a.cinvcode order by a.iQuantity desc FOR XML PATH('')
// ),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 * FROM ( select * FROM (select * from (select N'' as selcol,qmcheckvoucher.ddate,ccheckcode,ccheckpersoncode,
person.cpersonname as ccheckpersonname,darrivaldate,sourcecode,
pu_arrivalvouch.cptcode,cptname,cbustype,qmcheckvoucher.cvencode,
pu_arrivalvouch.cexch_name,pu_arrivalvouch.idiscounttaxtype,pu_arrivalvouch.iexchrate,
vendor.iid as vendoriid,vendor.cvenabbname as cvenname,cinspectdepcode,
department.cdepname as cinspectdepname,pu_arrivalvouch.cpersoncode,
person1.cpersonname,pu_arrivalvouch.cmemo,
qmcheckvoucher.cdefine1,qmcheckvoucher.cdefine2,qmcheckvoucher.cdefine3,
qmcheckvoucher.cdefine4,qmcheckvoucher.cdefine5,qmcheckvoucher.cdefine6,
qmcheckvoucher.cdefine7,qmcheckvoucher.cdefine8,qmcheckvoucher.cdefine9,
qmcheckvoucher.cdefine10,qmcheckvoucher.cdefine11,qmcheckvoucher.cdefine12,
qmcheckvoucher.cdefine13,qmcheckvoucher.cdefine14,qmcheckvoucher.cdefine15,
qmcheckvoucher.cdefine16,
qmcheckvoucher.cwhcode,cwhname,purchasetype.crdcode,
crdname,qmcheckvoucher.cinvcode,Inventory.cinvaddcode,Inventory.cinvname,Inventory.cinvstd,
cinvdefine1,cinvdefine2,cinvdefine3,cinvdefine4,cinvdefine5,cinvdefine6,
cinvdefine7,cinvdefine8,cinvdefine9,cinvdefine10,cinvdefine11,cinvdefine12,
cinvdefine13,cinvdefine14 , cinvdefine15, cinvdefine16,
qmcheckvoucher.cfree1,qmcheckvoucher.cfree2,qmcheckvoucher.cfree3,
qmcheckvoucher.cfree4,qmcheckvoucher.cfree5,qmcheckvoucher.cfree6,
qmcheckvoucher.cfree7,qmcheckvoucher.cfree8,qmcheckvoucher.cfree9,
qmcheckvoucher.cfree10,
pu_arrivalvouchs.ivouchrowno,
qmcheckvoucher.cBatch , dprodate, pu_arrivalvouchs.imassdate, qmcheckvoucher.dvdate,
qmcheckvoucher.iExpiratDateCalcu,qmcheckvoucher.cExpirationdate,qmcheckvoucher.dExpirationdate,
computationunit.ccomunitname,computationunit1.ccomunitname as cunitname,
Case IsNull(inventory.iGroupType, 0) When 0 then 0 When 1 then (case isnull(ifregbreakqtydealtype,0) when 1 then (isnull(fregquantity,0)+isnull(fconquantiy,0)-isnull(FsumQuantity ,0))/computationunit1.ichangrate else (isnull(fregquantity,0)+isnull(fconquantiy,0)-isnull(FREGBREAKQUANTITY,0)*isnull(FCHECKRATE,1)-isnull(FsumQuantity ,0))/computationunit1.ichangrate end) When 2 then (case isnull(ifregbreakqtydealtype,0) when 1 then (isnull(fchecknum,0)-isnull(FsumNum ,0)) else (isnull(fchecknum,0)-isnull(FsumNum ,0)-isnull(FREGBREAKQUANTITY,0)*isnull(FCHECKRATE,1)/fcheckchangrate) end) End as fnum,icost as fcost,iinvrcost as finvrcost,
Case IsNull(inventory.iGroupType, 0) When 0 then (case isnull(ifregbreakqtydealtype,0) when 1 then (isnull(fregquantity,0)+isnull(fconquantiy,0)-isnull(FsumQuantity ,0)) else (isnull(fregquantity,0)+isnull(fconquantiy,0)-isnull(FREGBREAKQUANTITY,0)*isnull(FCHECKRATE,1)-isnull(FsumQuantity ,0)) end) When 1 then (case isnull(ifregbreakqtydealtype,0) when 1 then (isnull(fregquantity,0)+isnull(fconquantiy,0)-isnull(FsumQuantity ,0)) else (isnull(fregquantity,0)+isnull(fconquantiy,0)-isnull(FREGBREAKQUANTITY,0)*isnull(FCHECKRATE,1)-isnull(FsumQuantity ,0)) end) When 2 then (case isnull(ifregbreakqtydealtype,0) when 1 then (isnull(fcheckqty,0)-isnull(Fsumquantity ,0)) else (isnull(fcheckqty,0)-isnull(Fsumquantity ,0)-isnull(FREGBREAKQUANTITY,0)*isnull(FCHECKRATE,1)) end) End as fquantity,((isnull(fregquantity,0)+isnull(fconquantiy,0))*pu_arrivalvouchs.imoney/pu_arrivalvouchs.iquantity) as fmoney,
((isnull(fregquantity,0)+isnull(fconquantiy,0))*iinvrcost) as finvrmoney,
pu_arrivalvouchs.cdefine22,pu_arrivalvouchs.cdefine23,pu_arrivalvouchs.cdefine24,pu_arrivalvouchs.cdefine25,pu_arrivalvouchs.cdefine26,pu_arrivalvouchs.cdefine27,pu_arrivalvouchs.cdefine28,pu_arrivalvouchs.cdefine29,pu_arrivalvouchs.cdefine30,pu_arrivalvouchs.cdefine31,pu_arrivalvouchs.cdefine32,pu_arrivalvouchs.cdefine33,pu_arrivalvouchs.cdefine34,pu_arrivalvouchs.cdefine35,pu_arrivalvouchs.cdefine36,pu_arrivalvouchs.cdefine37,
qmcheckvoucher.id,sourceautoid,inventory.ccomunitcode,
qmcheckvoucher.cunitid,citemclass,citemcname,qmcheckvoucher.citemcode,qmcheckvoucher.citemname,
(case when bfree1=1 then N'是' else N'否' end) as bfree1,
(case when bfree2=1 then N'是' else N'否' end) as bfree2,
(case when bfree3=1 then N'是' else N'否' end) as bfree3,
(case when bfree4=1 then N'是' else N'否' end) as bfree4,
(case when bfree5=1 then N'是' else N'否' end) as bfree5,
(case when bfree6=1 then N'是' else N'否' end) as bfree6,
(case when bfree7=1 then N'是' else N'否' end) as bfree7,
(case when bfree8=1 then N'是' else N'否' end) as bfree8,
(case when bfree9=1 then N'是' else N'否' end) as bfree9,
(case when bfree10=1 then N'是' else N'否' end) as bfree10,
inventory.cgroupcode,igrouptype,
(case when bservice=1 then N'是' else N'否' end) as bservice,
(case when binvbatch=1 then N'是' else N'否' end) as binvbatch,
convert(char,convert(money,qmcheckvoucher.ufts),2) as ufts,
(Case pu_arrivalvouchs.cmassunit When 1 then N'年' when 2 then N'月' when 3 then N'日' else N'' End) as cmassunit,
qmcheckvoucher.iordertype,
qmcheckvoucher.CSOORDERCODE as csocode, CASE qmcheckvoucher.iordertype WHEN 1 THEN SO_SODETAILS.IROWNO WHEN 3 THEN EX_ORDERDETAIL.IROWNO ELSE NULL END As isoseq, qmcheckvoucher.ISOORDERAUTOID as iSoDID,
qmcheckvoucher.IORDERDID,qmcheckvoucher.ISOORDERTYPE,qmcheckvoucher.CORDERCODE,qmcheckvoucher.IORDERSEQ,
qmcheckvoucher.CBATCHPROPERTY1,qmcheckvoucher.CBATCHPROPERTY2,qmcheckvoucher.CBATCHPROPERTY3,
qmcheckvoucher.CBATCHPROPERTY4,qmcheckvoucher.CBATCHPROPERTY5,qmcheckvoucher.CBATCHPROPERTY6,
qmcheckvoucher.CBATCHPROPERTY7,qmcheckvoucher.CBATCHPROPERTY8,qmcheckvoucher.CBATCHPROPERTY9,
qmcheckvoucher.CBATCHPROPERTY10,
inventory.iid, qmcheckvoucher.ccontractstrcode,qmcheckvoucher.ccontractcode, Case IsNull(inventory.iGroupType, 0) when 0 then null when 1 then computationunit1.ichangrate when 2 then (case isnull(ifregbreakqtydealtype,0) when 1 then case (isnull(fchecknum,0)-isnull(FsumNum ,0)) when 0 then null else
(isnull(fcheckqty,0)-isnull(FsumQuantity,0))/(isnull(fchecknum,0)-isnull(FsumNum ,0)) end Else Case (IsNull(fchecknum, 0) - IsNull(FsumNum, 0) - IsNull(FREGBREAKQUANTITY, 0) * isnull(FCHECKRATE,1) / fcheckchangrate) when 0 then null else
(isnull(fcheckqty,0)-isnull(FsumQuantity,0)-isnull(FREGBREAKQUANTITY,0)*isnull(FCHECKRATE,1))/(isnull(fchecknum,0)-isnull(FsumNum ,0)-isnull(FREGBREAKQUANTITY,0)*isnull(FCHECKRATE,1)/fcheckchangrate) end end) end As fchangrate,isnull(QMCheckVoucher.BEXIGENCY,0) as BEXIGENCY,
pu_arrivalvouch.cvenpuomprotocol,aa_agreement.cname as cvenpuomprotocolname,pu_arrivalvouchs.cciqbookcode,pu_arrivalvouch.iflowid as iflowid,pubizflow.cflowname as cflowname,qmcheckvoucher.fsampqty,qmcheckvoucher.FSAMPQTYINS from qmcheckvoucher
inner join inventory on qmcheckvoucher.cinvcode=inventory.cinvcode
inner join pu_arrivalvouchs on qmcheckvoucher.sourceautoid=pu_arrivalvouchs.autoid
inner join pu_arrivalvouch on pu_arrivalvouchs.id=pu_arrivalvouch.id
left join pubizflow on pubizflow.iflowid=pu_arrivalvouch.iflowid
left join person on qmcheckvoucher.ccheckpersoncode=person.cpersoncode
left join purchasetype on pu_arrivalvouch.cptcode=purchasetype.cptcode
left join vendor on qmcheckvoucher.cvencode=vendor.cvencode
left join department on qmcheckvoucher.cinspectdepcode=department.cdepcode
left join person as person1 on pu_arrivalvouch.cpersoncode=person1.cpersoncode
left join warehouse on qmcheckvoucher.cwhcode=warehouse.cwhcode
left join rd_style on purchasetype .crdcode=rd_style.crdcode
left join computationunit on inventory.ccomunitcode=computationunit.ccomunitcode
left join computationunit as computationunit1 on qmcheckvoucher.cunitid = computationunit1.ccomunitcode
left join aa_agreement on pu_arrivalvouch.cvenpuomprotocol = aa_agreement.ccode
LEFT OUTER JOIN SO_SODETAILS ON QMCHECKVOUCHER.IORDERTYPE =1 and cast(SO_SODETAILS.ISOSID as nvarchar(50))=qmcheckvoucher.ISOORDERAUTOID
LEFT OUTER JOIN EX_ORDERDETAIL ON QMCHECKVOUCHER.IORDERTYPE =3 and cast(EX_ORDERDETAIL.AUTOID as nvarchar(50))=qmcheckvoucher.ISOORDERAUTOID
where isnull(qmcheckvoucher.cverifier,N'')<>N'' and isnull(bpuinflag,0)=0 and qmcheckvoucher.cvouchtype=N'qm03' and (isnull(fregquantity,0)+isnull(fconquantiy,0))>0 AND isnull(pu_arrivalvouchs.CBCLOSER,'') = '' )
as aa where 1=1 and ( (1>0) AND (1>0) ) AND ( 1=1 )) as QMList ) as tmp ";
if (!string.IsNullOrEmpty(where))
{
strSQL += "where 1=1 and " + where;
}
return conn.Query<Model.Qmcheck.Qmcheckvoucher>(strSQL, param);
}
}
public IEnumerable<Model.Qmcheck.Qmcheckvoucher> GetListByCcheckcode(string Code)
{
return this.GetList(" ccheckcode=@Code", new { Code });
}
public Model.Qmcheck.Qmcheckvoucher GetModel(string Code)
{
return this.GetList(" ccheckcode=@Code", new { Code }).FirstOrDefault();
}
}
}