📄 lrfx.~pas
字号:
unit lrfx;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ComCtrls, ExtCtrls, Grids, DBGrids, Buttons, DB,main;
type
Tf_lrfx = class(TForm)
Panel1: TPanel;
Panel2: TPanel;
Label2: TLabel;
czy: TEdit;
Label3: TLabel;
sj: TDateTimePicker;
Panel3: TPanel;
Label1: TLabel;
Panel4: TPanel;
Panel5: TPanel;
Panel7: TPanel;
Label4: TLabel;
Splitter1: TSplitter;
Label5: TLabel;
Label6: TLabel;
xslr: TEdit;
thflr: TEdit;
Panel6: TPanel;
Label7: TLabel;
Label8: TLabel;
Label9: TLabel;
xssl: TEdit;
xsje: TEdit;
Splitter2: TSplitter;
Panel8: TPanel;
Label10: TLabel;
Label11: TLabel;
Label12: TLabel;
thsl: TEdit;
thje: TEdit;
Splitter3: TSplitter;
cx: TBitBtn;
BitBtn2: TBitBtn;
Label13: TLabel;
zlr: TEdit;
DataSource1: TDataSource;
DataSource2: TDataSource;
DBGrid1: TDBGrid;
DBGrid2: TDBGrid;
Label14: TLabel;
thlr: TEdit;
procedure cxClick(Sender: TObject);
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
public
procedure clearedit;
{ Public declarations }
end;
var
f_lrfx: Tf_lrfx;
implementation
uses DataModal;
{$R *.dfm}
procedure Tf_lrfx.clearedit;
begin
xssl.Clear;
xsje.Clear;
thsl.Clear;
thje.Clear;
xslr.Clear;
thlr.Clear;
thflr.Clear;
zlr.Clear;
end;
procedure Tf_lrfx.cxClick(Sender: TObject);
var
year,month,Day: Word;
Days: Integer;//记录当前月的天数
xsPrice,thPrice,cbPrice,bzsj,cbj: real;
xsSum,thsum: Integer;
thgain,thfgain: Real;//退货利润,退货负利润 在退货时,退货金额小于销售金额会产生退货利润
begin
Days := 30;
thfgain :=0.0;
xsprice := 0.0;
thgain := 0.0;
cbPrice := 0.0;
cbj := 0.0;
xssum := 0;
DecodeDate(sj.DateTime,year,month,day);
with Data.Query1 do
begin
Close;
SQL.Clear;
SQL.Add('select aa.xsph,aa.kcmc,aa.spdm,bb.spmc,aa.jbdw,aa.num,aa.bzsj,aa.zk,aa.sl,aa.se,aa.wzrje,aa.je,aa.bzq from ');
SQL.Add('t_xsmx aa inner join t_spjcxx bb on aa.spdm = bb.spdm and aa.xsph in (select xsph from t_xsph where sj >= :a and sj<:b) ');
ParamByName('a').AsFloat := Trunc(sj.Date)-Day+1-2; //取当前月初的整数值,减2是为了与SQL Server中的数值对应
Case Month of
1,3,5,7,8,10,12: Days := 31;
2: begin
if isLeapYear(Year)=True then
Days :=29
else
Days := 28
end;
4,6,9: Days := 30;
end;
ParamByName('b').AsFloat :=Trunc(sj.Date)-Day+Days+0.998-2;//取当前月末的整数值,减2是为了与SQL Server中的数值对应
Open;
if RecordCount>0 then
begin
while Not Data.Query1.Eof do
begin
with Data.Query3 do
begin
Close;
SQL.Clear;
SQL.Add('select cbj from t_ycbhs where sj >= :a and sj <:b and spdm = :c');
ParamByName('a').AsFloat := Trunc(sj.Date)-Day+1-2; //取当前月初的整数值,减2是为了与SQL Server中的数值对应
Case Month of
1,3,5,7,8,10,12: Days := 31;
2: begin
if isLeapYear(Year)=True then
Days :=29
else
Days := 28
end;
4,6,9: Days := 30;
end;
ParamByName('b').AsFloat :=Trunc(sj.Date)-Day+Days+0.998-2;
ParamByName('c').AsString := Trim(Data.Query1.FieldByName('spdm').AsString);
Open;
end;
if Data.Query3.RecordCount>0 then
begin
cbprice := cbprice + Data.Query1.FieldByName('num').AsInteger*Data.Query3.FieldByName('cbj').AsFloat;
end
else
begin
Application.MessageBox(Pchar('商品编号为'+Data.Query1.FieldByName('spdm').AsString+'的商品本月没有统计成本价,不能完成查询.' ),'提示',64);
ClearEdit;
Exit;
end;
xsPrice := xsPrice + Data.Query1.FieldByName('je').AsFloat;
xssum := xssum + Data.Query1.FieldByName('num').AsInteger;
Data.Query1.Next;
end;
xslr.Text := FloatToStr(xsprice-cbPrice);
xsje.Text := FloatToStr(xsPrice);
xssl.Text := IntToStr(xssum);
Data.Query1.First;
DataSource1.DataSet := Data.Query1;
end
else
begin
DataSource1.DataSet := Nil;
DataSource2.DataSet := Nil;
ClearEdit;
Application.MessageBox('该月没有销售商品.','提示',64);
Exit;
end;
end;
with Data.Query2 do
begin
Close;
SQL.Clear;
SQL.Add('select aa.thph,aa.kcmc,aa.spdm,bb.spmc,aa.jbdw,aa.sl,aa.zk,aa.je,aa.bzq from ');
SQL.Add('t_xsthmx aa inner join t_spjcxx bb on aa.spdm = bb.spdm and aa.thph in (select thph from t_xsthph where sj >= :a and sj<:b) ');
ParamByName('a').AsFloat := Trunc(sj.Date)-Day+1-2; //取当前月初的整数值,减2是为了与SQL Server中的数值对应
Case Month of
1,3,5,7,8,10,12: Days := 31;
2: begin
if isLeapYear(Year)=True then
Days :=29
else
Days := 28
end;
4,6,9: Days := 30;
end;
ParamByName('b').AsFloat :=Trunc(sj.Date)-Day+Days+0.998-2;//取当前月末的整数值,减2是为了与SQL Server中的数值对应
Open;
if RecordCount>0 then
begin
DataSource2.DataSet := Data.Query2;
with Data.Query3 do
begin
Close;
SQL.Clear;
SQL.Add('select sum(czje)as czje from t_xsthph where sj >= :a and sj <:b');
ParamByName('a').AsFloat := Trunc(sj.Date)-Day+1-2;
Case Month of
1,3,5,7,8,10,12: Days := 31;
2: begin
if isLeapYear(Year)=True then
Days :=29
else
Days := 28
end;
4,6,9: Days := 30;
end;
ParamByName('b').AsFloat :=Trunc(sj.Date)-Day+Days+0.998-2;
Open;
end;
thPrice := Data.Query3.Fields[0].AsFloat;
thje.Text := FloatToStr(thPrice);
with Data.Query3 do
begin
Close;
SQL.Clear;
SQL.Add('select sum(sl) as sl from t_xsthmx where thph in(select thph from t_xsthph where sj>=:a and sj <:b)');
ParamByName('a').AsFloat := Trunc(sj.Date)-Day+1-2; //取当前月初的整数值,减2是为了与SQL Server中的数值对应
Case Month of
1,3,5,7,8,10,12: Days := 31;
2: begin
if isLeapYear(Year)=True then
Days :=29
else
Days := 28
end;
4,6,9: Days := 30;
end;
ParamByName('b').AsFloat :=Trunc(sj.Date)-Day+Days+0.998-2;//取当前月末的整数值,减2是为了与SQL Server中的数值对应
Open;
end;
thsum := Data.Query3.Fields[0].Asinteger;
thsl.Text := IntToStr(thsum);
Data.Query2.First;
while Not Data.Query2.Eof do
begin
with Data.Query3 do
begin
Close;
SQL.Clear;
SQL.Add('select bzsj from t_spsj where spdm = :a');
ParamByName('a').AsString := Trim(Data.Query2.FieldByName('spdm').AsString);
Open;
end;
bzsj := Data.Query3.Fields[0].AsFloat;
with Data.Query3 do
begin
Close;
SQL.Clear;
SQL.Add('select cbj from t_ycbhs where sj>=:a and sj<:b and spdm = :c');
ParamByName('a').AsFloat := Trunc(sj.Date)-Day+1-2; //取当前月初的整数值,减2是为了与SQL Server中的数值对应
Case Month of
1,3,5,7,8,10,12: Days := 31;
2: begin
if isLeapYear(Year)=True then
Days :=29
else
Days := 28
end;
4,6,9: Days := 30;
end;
ParamByName('b').AsFloat :=Trunc(sj.Date)-Day+Days+0.998-2;
ParamByName('c').AsString := Trim(Data.Query2.FieldByName('spdm').AsString);
Open;
end;
if Data.Query3.RecordCount>0 then
begin
cbj := Data.Query3.Fields[0].AsFloat;
end
else
begin
Application.MessageBox(Pchar('商品编号为'+Data.Query1.FieldByName('spdm').AsString+'的商品本月没有统计成本价,不能完成统计.' ),'提示',64);
Exit;
end;
thfgain := thfgain + (bzsj-cbj)*Data.Query2.FieldByName('sl').AsInteger;
thgain := thgain + bzsj*Data.Query2.FieldByName('sl').AsInteger-Data.Query2.FieldByName('je').AsFloat;
Data.Query2.Next;
end;
Data.Query2.First;
thlr.Text := Format('%8.4f',[thgain]);
thflr.Text := Format('%8.4f',[thfgain]);
end
else
begin
DataSource2.DataSet := Nil;
thsl.Clear;
thlr.Clear;
thje.Clear;
thflr.Clear;
end;
end;
zlr.Text := Format('%8.4f',[xsprice-cbPrice-thfgain+thgain]); //xsprice-cbPrice为销售利润,总利润等于销售利润-退货负利润+退货利润
end;
procedure Tf_lrfx.FormCreate(Sender: TObject);
begin
sj.DateTime := Now;
czy.Text := Trim(czyxx.czymc);
end;
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -