📄 unit_rubb_wassum.~pas
字号:
unit Unit_Rubb_WasSum;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
DBTables, Db, Grids, DBGrids, StdCtrls, Buttons, ExtCtrls;
type
TForm_Rubb_WasSum = class(TForm)
DBGrid1: TDBGrid;
Query1: TQuery;
Query2: TQuery;
Query3: TQuery;
BitBtn2: TBitBtn;
BitBtn3: TBitBtn;
Panel1: TPanel;
labDate: TLabel;
Label1: TLabel;
labCurdate: TLabel;
Bevel1: TBevel;
Button1: TButton;
Label2: TLabel;
procedure FormClose(Sender: TObject; var Action: TCloseAction);
procedure BitBtn3Click(Sender: TObject);
procedure BitBtn2Click(Sender: TObject);
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
procedure zdyWasSum(dFrom,dTo:TDate);
end;
var
Form_Rubb_WasSum: TForm_Rubb_WasSum;
implementation
uses UnitDM, Unit_Rubb_WasSumPrt, Unit_Rubb_SumCfg;
{$R *.DFM}
procedure TForm_Rubb_WasSum.zdyWasSum(dFrom,dTo:TDate);
var
sRubbName,sProdID:string;
fLastStock,fThisIn,fThisStock,fWeight,fThisProdWeight,fLoss,fPer,thisout,yingkuei:real;
iNumber:integer;
begin
//======清空月报表====
with dm.table1 do
begin
close;
emptytable;
end; //with
//选出胶料名称
with query1 do
begin
// while not eof do
close;
sql.clear;
sql.add('select 胶料名称 from 炼胶台帐 group by 胶料名称 ');
open;
first;
// showmessage(fieldbyname('胶料名称').asstring);
while not eof do
begin
sRubbName:=fieldbyname('胶料名称').asstring;
//====得到本月库存======
// 上月结存
with query2 do
begin
close;
sql.clear;
sql.add('select 结存 from 炼胶台帐 where 日期 <= :vdate and 胶料名称 = :sRubbName'); //?=
parambyname('vdate').asdatetime:= dFrom;
parambyname('sRubbName').asstring:= sRubbName;
open;
last;
fLastStock:=fieldbyname('结存').asfloat;
end; //with
// 本月入库
with query2 do
begin
close;
sql.clear;
//sql.add('select Sum(入库数量) from 炼胶台帐 where 日期 between :vfrom and :vto and 胶料名称 = :sRubbName');
sql.add('select Sum(入库数量) from 炼胶台帐 where 日期 > :vfrom and 日期<=:vto and 胶料名称 = :sRubbName');
parambyname('vfrom').asdatetime:= dFrom;
parambyname('vto').asdatetime:= dto;
parambyname('sRubbName').asstring:= sRubbName;
open;
fThisIn:=fields[0].asfloat;
end; //with
//本月出库
with query2 do
begin
close;
sql.clear;
//sql.add('select Sum(合计) from 炼胶台帐 where 日期 between :vfrom and :vto and 胶料名称 = :sRubbName');
sql.add('select Sum(合计) from 炼胶台帐 where 日期 > :vfrom and 日期<=:vto and 胶料名称 = :sRubbName');
parambyname('vfrom').asdatetime:= dFrom;
parambyname('vto').asdatetime:= dto;
parambyname('sRubbName').asstring:= sRubbName;
open;
thisout:=fields[0].asfloat;
end; //with
with query2 do
begin
close;
sql.clear;
//sql.add('select Sum(盈亏) from 炼胶台帐 where 日期 between :vfrom and :vto and 胶料名称 = :sRubbName');
sql.add('select Sum(盈亏) from 炼胶台帐 where 日期 > :vfrom and 日期<=:vto and 胶料名称 = :sRubbName');
parambyname('vfrom').asdatetime:= dFrom;
parambyname('vto').asdatetime:= dto;
parambyname('sRubbName').asstring:= sRubbName;
open;
yingkuei:=fields[0].asfloat;
end;
// 成品重量
with query2 do
begin
close;
sql.clear;
sql.add('select * from ProdDictionary where RubbName = :sRubbNam');
parambyname('sRubbNam').asstring:= sRubbName;
open;
first;
// showmessage(inttostr(recordcount));
end;
fThisProdWeight:=0;
with query2 do
begin
while not eof do
begin
sProdID:=fieldbyname('ProdID').asstring;
fWeight:=fieldbyname('Weight').asfloat;
query3.close;
query3.sql.clear;
query3.sql.add('select sum(Number) from ProdInCard');
query3.sql.add('where Indate >:vfrom and Indate<=:vto ');
query3.sql.add('and prodID = :ProdI ');
query3.parambyname('vfrom').asdatetime:=dfrom;
query3.parambyname('vto').asdatetime:=dto;
query3.parambyname('ProdI').asstring:=sProdID;
query3.open;
iNumber:=query3.fields[0].asinteger;
fThisProdWeight:=fThisProdWeight+iNumber * fWeight/1000;
next;
end;
// next;
end; // while
with query2 do //本月库存
begin
close;
sql.clear;
//sql.add('select * from 炼胶台帐 where 日期 between :vfrom and :vto and 胶料名称 = :sRubbName');
sql.add('select * from 炼胶台帐 where 日期 >:vfrom and 日期<=:vto and 胶料名称 = :sRubbName');
parambyname('vfrom').asdatetime:= dFrom;
parambyname('vto').asdatetime:= dto;
parambyname('sRubbName').asstring:= sRubbName;
open;
last;
if recordcount <> 0 then
fThisStock:=fieldbyname('结存').asfloat;
if recordcount = 0 then
fThisStock:=fLastStock;
end; //with
// 得到损耗
//fThisIn:=fThisIn+yingkuei;
fLoss:=fLastStock + fThisIn+yingkuei - fThisProdWeight - fThisStock;
//百分率
if thisout = 0 then
fPer:=100
else
begin
//fPer:= fThisProdWeight /(fLastStock + fThisIn - fThisStock);
fPer:= (fThisProdWeight /thisout)*100;
fPer:= strtofloat(formatfloat('0.00',fPer));
//fPer:= fPer * 100;
end; //if
//======填写报表=====
with dm.table1 do
begin
open;
insert;
fieldbyname('本月出库').asfloat:=thisout;
fieldbyname('胶料名称').asstring:=sRubbName;
fieldbyname('上月结存').asfloat:=fLastStock;
fieldbyname('本月入库').asfloat:=fThisIn+yingkuei;
fieldbyname('成品重量').asfloat:=fThisProdWeight;
fieldbyname('本月库存').asfloat:=fThisStock;
fieldbyname('损耗').asfloat:=fLoss;
fieldbyname('百分率').asfloat:=fPer;
post;
end; //with
next;
end; //while
end; //with query1
with dm.table2 do
begin
open;
append;
fieldbyname('JDate').asdatetime:=dTo;
// fieldbyname('JDate').asdatetime:=Form_Rubb_SumCfg.DateTimePicker_To.date;
post;
close;
end; //with
Form_Rubb_SumCfg.zdyjiaoCheckDiary();// 显示修改后的结帐表
query1.close;
query2.close;
query3.close;
end;
procedure TForm_Rubb_WasSum.FormClose(Sender: TObject;
var Action: TCloseAction);
begin
dm.zdyGetjiaoCheckDate;
Form_Rubb_SumCfg.zdyjiaoCheckDiary(); //显示结帐日期表
dm.table1.close;
end;
procedure TForm_Rubb_WasSum.BitBtn3Click(Sender: TObject);
begin
with Form_Rubb_WasSumPrt do
begin
QRLab_DateRange.caption:=labDate.caption;
qrcurdate.caption:=labCurdate.caption;
QuickRep1.Preview;
end; //with
end;
procedure TForm_Rubb_WasSum.BitBtn2Click(Sender: TObject);
begin
with Form_Rubb_WasSumPrt do
begin
QRLab_DateRange.caption:=labDate.caption;
qrcurdate.caption:=labCurdate.caption;
QuickRep1.print;
end; //with
end;
procedure TForm_Rubb_WasSum.Button1Click(Sender: TObject);
begin
dm.table1.close;
close;
end;
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -