分享
 
 
 

GetPartFilter+SumStocklist

王朝delphi·作者佚名  2006-01-09
窄屏简体版  字體: |||超大  

sql.text:= 'insert into Rep仓库收付存月结报表(MC,ycjcje,bqsrje,bqllje,qmjcje) '+

' (select sorttype,sum(qc*inprice),sum((rk-rkt)*inprice),sum((ck-ckt)*inprice),sum(jc*inprice) '+

' from tmpkk2 where 1=1 '+sdepot+stmp +' group by sorttype )' ;

ExecSQL;

function GetPartFilter(AID: string): string;

var

querytemp: TOceanQuery;

s: string;

lOwnerids: TStringList;

procedure GetOwnerids(AID: string);

var lQuery: TOceanQuery;

begin

lQuery := TOceanQuery.Create(nil);

try

lQuery.Close;

lQuery.SQL.Text := 'select ID from PartInfo where Ownerid=' + QuotedStr(AID) + ' and ID<>' + QuotedStr(AID) + ' and ImageIndex=0';

lQuery.Open;

while not lQuery.Eof do

begin

lOwnerids.Add(lQuery.FieldByName('ID').AsString);

GetOwnerids(lQuery.FieldByName('ID').AsString);

lQuery.Next;

end;

finally

lQuery.Free;

end;

end;

var I: Integer;

begin

Result := '';

querytemp := TOceanQuery.Create(nil);

lOwnerids := TStringList.Create;

try

querytemp.Close;

querytemp.SQL.Text := 'select ID,ImageIndex from partinfo where ID=''' + AID + '''';

querytemp.Open;

if querytemp.IsEmpty then Exit;

if querytemp.FieldByName('ImageIndex').AsInteger <> 0 then

begin

Result := 'ID=' + QuotedStr(AID);

Exit;

end;

lOwnerids.Add(querytemp.FieldByName('ID').AsString);

GetOwnerids(querytemp.FieldByName('ID').AsString);

for I := 0 to lOwnerids.Count - 1 do

begin

if Result = '' then

Result := 'Ownerid in (' + QuotedStr(lOwnerids[I])

else

Result := Result + ',' + QuotedStr(lOwnerids[I]);

end;

if Result <> '' then

Result := Result + ')';

finally

querytemp.Free;

lOwnerids.Free;

end;

end;

function sumStocklist(Aid: string; Aimaindex: integer; Adepotcode: string; time1, time2: Tdate; llist: Tstringlist): Tstringlist;

var

s, sdate, sdepot: string;

myOceanQry: TOceanQuery;

stmp: string;

qichu1,qichu2:string;

sumJC, sumJCsj, sumQC, sumQCsj, sumRK, sumRKsj, sumLY, sumLYsj, sumLT, sumLTsj, sumRT, sumRTsj: integer;

begin

myOceanQry := TOceanQuery.Create(nil);

try

if Aimaindex = 1 then

stmp := ' and partid=' + QuotedStr(AId)

else

stmp := ' and ' + GetPartFilter(Aid);

with myOceanQry do

begin

Close;

sql.text:= ' if exists (select * from sysobjects where id = object_id(N''[tmpkk2]'') and '+

' OBJECTPROPERTY(id, N''IsUserTable'') = 1) drop table [tmpkk2] ' ;

ExecSQL;

Close;

sql.text:='exec sp_stockSFC_depot_price '+QuotedStr(datetostr(time1)) +','+QuotedStr(datetostr(time2));

ExecSQL;

Close;

sql.text:=' select sum(qc) as qc,sum(rk) as rk ,sum(ck) as ck ,'+

' sum(rkt) as rkt ,sum(ckt) as ckt ,sum(jc) as jc '+

' from tmpkk2 where indepotcode='+ QuotedStr(Adepotcode)+stmp ;

open;

end;

llist.Add(inttostr(myOceanQry.fieldbyname('rk').Asinteger)); //strings[0] //入库票据

llist.Add(inttostr(myOceanQry.fieldbyname('rk').Asinteger)); //strings[1] //入库实际

llist.Add(inttostr(myOceanQry.fieldbyname('ck').Asinteger)); //strings[2] //领用票据

llist.Add(inttostr(myOceanQry.fieldbyname('ck').Asinteger)); //strings[3] //领用实际

llist.Add(inttostr(myOceanQry.fieldbyname('rkt').Asinteger)); //strings[4] //入库退货票据

llist.Add(inttostr(myOceanQry.fieldbyname('rkt').Asinteger)); //strings[5] //入库退货实际

llist.Add(inttostr(myOceanQry.fieldbyname('ckt').Asinteger)); //strings[6] //领用退货票据

llist.Add(inttostr(myOceanQry.fieldbyname('ckt').Asinteger)); //strings[7] //领用退货实际

llist.Add(inttostr(myOceanQry.fieldbyname('jc').Asinteger)); //strings[8] //结存票据

llist.Add(inttostr(myOceanQry.fieldbyname('jc').Asinteger)); //strings[9] //结存实际

llist.Add(inttostr(myOceanQry.fieldbyname('qc').Asinteger)); //strings[10] //期初票据

llist.Add(inttostr(myOceanQry.fieldbyname('qc').Asinteger)); //strings[11] //期初实际

Result := llist;

finally

myOceanQry.Free;

end;

end;

{

CREATE PROCEDURE sp_StockSFC_depot_price

@date1 datetime,

@date2 datetime

AS

select * into tmpkk2 from

(

SELECT ISNULL(a.Expr1, 0) AS xh, ISNULL(b.Expr1, 0) AS jc, b.Expr1 - a.Expr1 AS qc,

b.PARTNAME,b.partid,ownerid=(select ownerid from partinfo where id=b.partid),

sorttype=(select sorttype from partinfo where id=b.partid),

a.rk,a.rkt,a.ck,a.ckt,b.inprice,b.outprice,b.indepotcode,b.outdepotcode

FROM (

SELECT isnull(tmp1.sumquantity, 0) - isnull(tmp2.sumquantity, 0)

- isnull(tmp3.sumquantity, 0) + isnull(tmp4.sumquantity, 0) AS Expr1,

isnull(tmp1.sumquantity,0) as rk,isnull(tmp2.sumquantity,0) as ck,

isnull(tmp3.sumquantity,0) as rkt,isnull(tmp4.sumquantity,0) as ckt,

TMP.PARTNAME, tmp.partid,tmp.depotcode as indepotcode,tmp2.depotcode as outdepotcode

FROM (SELECT a.PARTID, a.PARTNAME,b.depotcode

FROM dbo.PARTSINPUTBODY a LEFT OUTER JOIN

dbo.PARTSINPUTHAND b ON a.BILLCODE = b.BILLCODE

WHERE (b.BILLDATE <= @date2)

GROUP BY a.PARTID, a.PARTNAME,b.depotcode) tmp LEFT OUTER JOIN

(SELECT a.PARTID, a.PARTNAME,b.depotcode, SUM(a.QUANTITY) AS sumquantity

FROM dbo.PARTSINPUTBODY a LEFT OUTER JOIN

dbo.PARTSINPUTHAND b ON a.BILLCODE = b.BILLCODE

WHERE (b.BILLDATE BETWEEN @date1 AND @date2)

GROUP BY a.PARTID, a.PARTNAME,b.depotcode) tmp1 ON

tmp.partid = tmp1.partid and tmp.depotcode=tmp1.depotcode LEFT OUTER JOIN

(SELECT a.PARTID, a.PARTNAME,b.depotcode, SUM(a.QUANTITY) AS sumquantity

FROM dbo.PARTSOUTPUTBODY a LEFT OUTER JOIN

dbo.PARTSOUTPUTHAND b ON a.BILLCODE = b.BILLCODE

WHERE (b.BILLDATE BETWEEN @date1 AND @date2)

GROUP BY a.PARTID, a.PARTNAME,b.depotcode) tmp2 ON

tmp.PARTID = tmp2.PARTID and tmp.depotcode=tmp2.depotcode LEFT OUTER JOIN

(SELECT isnull(SUM(a.quantity), 0) AS sumquantity, a.partid,b.depotcode

FROM reimbursebillbody a, reimbursebillhand b

WHERE a.billcode = b.billcode AND b.reimbursetype = '1' AND

b.isexecute = 1 AND b.billdate BETWEEN @date1 AND @date2

GROUP BY a.partid,b.depotcode) tmp3 ON

tmp.PARTID = tmp3.PARTID and tmp.depotcode=tmp3.depotcode LEFT OUTER JOIN

(SELECT isnull(SUM(a.quantity), 0) AS sumquantity, a.partid,b.depotcode

FROM reimbursebillbody a, reimbursebillhand b

WHERE a.billcode = b.billcode AND b.reimbursetype = '2' AND

b.isexecute = 1 AND b.billdate BETWEEN @date1 AND @date2

GROUP BY a.partid,b.depotcode) tmp4 ON

tmp.PARTID = tmp4.PARTID and tmp.depotcode=tmp4.depotcode)

a RIGHT OUTER JOIN

(SELECT isnull(tmp1.sumquantity, 0) - isnull(tmp2.sumquantity, 0)

- isnull(tmp3.sumquantity, 0) + isnull(tmp4.sumquantity, 0) AS Expr1,

TMP1.PARTNAME, tmp1.partid,tmp1.price as inprice,tmp2.price as outprice,

tmp1.depotcode as indepotcode,tmp2.depotcode as outdepotcode

FROM (

SELECT a.PARTID, a.PARTNAME,a.price,b.depotcode, SUM(a.QUANTITY) AS sumquantity

FROM dbo.PARTSINPUTBODY a LEFT OUTER JOIN

dbo.PARTSINPUTHAND b ON a.BILLCODE = b.BILLCODE

WHERE (b.BILLDATE <= @date2)

GROUP BY a.PARTID, a.PARTNAME,a.price,b.depotcode)

tmp1 LEFT OUTER JOIN

(SELECT a.PARTID, a.PARTNAME,a.price,b.depotcode, SUM(a.QUANTITY)

AS sumquantity

FROM dbo.PARTSOUTPUTBODY a LEFT OUTER JOIN

dbo.PARTSOUTPUTHAND b ON a.BILLCODE = b.BILLCODE

WHERE (b.BILLDATE <= @date2)

GROUP BY a.PARTID, a.PARTNAME,a.price,b.depotcode)

tmp2 ON

tmp1.PARTID = tmp2.PARTID and tmp1.depotcode=tmp2.depotcode LEFT OUTER JOIN

(SELECT isnull(SUM(a.quantity), 0) AS sumquantity, a.partid,b.depotcode

FROM reimbursebillbody a, reimbursebillhand b

WHERE a.billcode = b.billcode AND b.reimbursetype = '1' AND

b.isexecute = 1 AND b.billdate <= @date2

GROUP BY a.partid,b.depotcode) tmp3 ON

tmp1.PARTID = tmp3.PARTID and tmp1.depotcode=tmp3.depotcode LEFT OUTER JOIN

(SELECT isnull(SUM(a.quantity), 0) AS sumquantity, a.partid,b.depotcode

FROM reimbursebillbody a, reimbursebillhand b

WHERE a.billcode = b.billcode AND b.reimbursetype = '2' AND

b.isexecute = 1 AND b.billdate <= @date2

GROUP BY a.partid,b.depotcode) tmp4 ON tmp1.PARTID = tmp4.PARTID and tmp1.depotcode=tmp4.depotcode) b ON

a.partid = b.partid and a.indepotcode=b.indepotcode

) tqqq

GO

}

 
 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
2023年上半年GDP全球前十五强
 百态   2023-10-24
美众议院议长启动对拜登的弹劾调查
 百态   2023-09-13
上海、济南、武汉等多地出现不明坠落物
 探索   2023-09-06
印度或要将国名改为“巴拉特”
 百态   2023-09-06
男子为女友送行,买票不登机被捕
 百态   2023-08-20
手机地震预警功能怎么开?
 干货   2023-08-06
女子4年卖2套房花700多万做美容:不但没变美脸,面部还出现变形
 百态   2023-08-04
住户一楼被水淹 还冲来8头猪
 百态   2023-07-31
女子体内爬出大量瓜子状活虫
 百态   2023-07-25
地球连续35年收到神秘规律性信号,网友:不要回答!
 探索   2023-07-21
全球镓价格本周大涨27%
 探索   2023-07-09
钱都流向了那些不缺钱的人,苦都留给了能吃苦的人
 探索   2023-07-02
倩女手游刀客魅者强控制(强混乱强眩晕强睡眠)和对应控制抗性的关系
 百态   2020-08-20
美国5月9日最新疫情:美国确诊人数突破131万
 百态   2020-05-09
荷兰政府宣布将集体辞职
 干货   2020-04-30
倩女幽魂手游师徒任务情义春秋猜成语答案逍遥观:鹏程万里
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案神机营:射石饮羽
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案昆仑山:拔刀相助
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案天工阁:鬼斧神工
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案丝路古道:单枪匹马
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:与虎谋皮
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:李代桃僵
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:指鹿为马
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案金陵:小鸟依人
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案金陵:千金买邻
 干货   2019-11-12
 
推荐阅读
 
 
 
>>返回首頁<<
 
靜靜地坐在廢墟上,四周的荒凉一望無際,忽然覺得,淒涼也很美
© 2005- 王朝網路 版權所有