📄 gl_enter_startuseaccount.pas
字号:
unit Gl_Enter_StartUseAccount;
Interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
Base_Dialog, Db, AdODB, StdCtrls, ExtCtrls, ComCtrls, Mask;
Type
TFrm_Gl_Enter_StartUseAccount = Class(TFrm_Base_Dialog)
Label1: TLabel;
cmb_CashCtrl: TComboBox;
Label2: TLabel;
edt_Month: TEdit;
procedure Edt_BuyerCtrlTypeChange(Sender: TObject);
procedure btn_okClick(Sender: TObject);
procedure FormClose(Sender: TObject; var Action: TCloseAction);
procedure FormKeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
procedure btn_CancelClick(Sender: TObject);
procedure MEdt_AutoRunPSI1Change(Sender: TObject);
private
{ Private declarations }
FReadOnly:Boolean;
public
procedure InitForm(AdoConnection:TAdoConnection;ReadOnly:Boolean);
function isBalance:boolean;
function gatherlowlevel:boolean;
procedure sumnext(kmid:integer);
procedure getkmInfo(kmid:integer);
{ Public declarations }
end;
var
Frm_Gl_Enter_StartUseAccount: TFrm_Gl_Enter_StartUseAccount;
kmCode:string; //科目代码
kmlevel:integer; //科目级次
KmProperty : Integer;//科目性质
implementation
{$R *.DFM}
uses Sys_Global;
{ TFrm_Bas_Param }
procedure TFrm_Gl_Enter_StartUseAccount.getkmInfo(kmid:integer);
var AdoQry:TAdoQuery;
begin
AdoQry:=TAdoQuery.Create(self);
AdoQry.Connection:=dbconnect;
try
Executesql(AdoQry,'select kmCode,kmlevel,KmProperty from Gl_AccountSubject where kmid='+inttostr(kmid),0);
kmCode:=AdoQry.fieldbyname('kmCode').asstring;
kmlevel:=AdoQry.fieldbyname('kmlevel').asinteger;
KmProperty := AdoQry.fieldbyname('KmProperty').AsInteger;
finally
AdoQry.Free;
end;
end;
procedure TFrm_Gl_Enter_StartUseAccount.sumnext(kmid:integer);
function existslowlevel(kmid:integer):boolean;
var Qry:TAdoQuery;
begin
Result:=False;
try
Qry:=TAdoQuery.Create(self);
Qry.Connection:=dbconnect;
Executesql(Qry,'select * from Gl_AccountSubject where kmid='+inttostr(kmid),0);
kmCode:=Qry.fieldbyname('kmCode').asstring;
kmlevel:=Qry.fieldbyname('kmlevel').asinteger;
KmProperty := Qry.fieldbyname('KmProperty').AsInteger;
Executesql(Qry,'select * from Gl_AccountSubject where endkm<>1 and kmlevel='+inttostr(kmlevel+1)+' and kmCode like '+quotedstr(kmCode+'%'),0);
if Qry.RecordCount>0 then Result:=True;
finally
Qry.Free;
end;
end;
var sqltext:string;
AdoQry:TAdoQuery;
AdoQry1:TAdoQuery;
begin
AdoQry:=TAdoQuery.Create(self);
AdoQry.Connection:=dbconnect;
AdoQry1:=TAdoQuery.Create(self);
AdoQry1.Connection:=dbconnect;
try
if not existslowlevel(kmid) then
begin
Executesql(AdoQry1,'select sum(case when BalanceDirection=1 then isnull(FirstBalance,0) '
+' else 0 '
+' end ) as DBalance,'
+' Sum( case when BalanceDirection=2 then isnull(FirstBalance,0) '
+' else 0 '
+' end '
+' ) as CBalance,'
+' case when sum(case when BalanceDirection=1 then isnull(FirstBalance,0) '
+' else 0 '
+' end )'
+' -Sum( case when BalanceDirection=2 then isnull(FirstBalance,0) '
+' else 0 '
+' end '
+' ) >0 then 1 '
+' when sum(case when BalanceDirection=1 then isnull(FirstBalance,0) '
+' else 0 '
+' end )'
+' -Sum( case when BalanceDirection=2 then isnull(FirstBalance,0) '
+' else 0 '
+' end '
+' )<0 then 2 end as BalanceDirection,'
+' sum(case when BalanceDirection=1 then isnull(FirstfBalance,0) '
+' else 0 '
+' end ) as FDBalance,'
+' Sum( case when BalanceDirection=2 then isnull(FirstfBalance,0) '
+' else 0 '
+' end '
+' ) as FCBalalnce '
// +' sum(isnull(FirstfBalance,0)) as fFirstBalance '
+' from Gl_AccountSubjectBalance t1 '
+' join Gl_AccountSubject t2 on t1.kmid=t2.kmid '
+' and kmlevel='+inttostr(kmlevel+1)
+' and kmCode like '+quotedstr(kmCode+'%'),0);
sqltext:='update Gl_AccountSubjectBalance '
+' set FirstBalance=abs('+AdoQry1.fieldbyname('DBalance').asstring+'-('+AdoQry1.fieldbyname('CBalance').asstring+')),'
+' FirstfBalance=abs('+AdoQry1.fieldbyname('DBalance').asstring+'-('+AdoQry1.fieldbyname('CBalance').asstring+'))/FCurrencyRate, '
+' BalanceDirection = '+IIFString(AdoQry1.fieldbyname('BalanceDirection').AsString='','BalanceDirection',AdoQry1.fieldbyname('BalanceDirection').AsString)
+' where kmid='+inttostr(kmid);
Executesql(AdoQry,sqltext,1);
end
else
begin
Executesql(AdoQry,'select kmid from Gl_AccountSubject where endkm<>1 and kmlevel='+inttostr(kmlevel+1)+' and kmCode like '+quotedstr(kmCode+'%'),0);
while not AdoQry.Eof do
begin
sumnext(AdoQry.fieldbyname('kmid').asinteger);
getkmInfo(kmid);
Executesql(AdoQry1,'select sum(case when BalanceDirection=1 then isnull(FirstBalance,0) '
+' else 0 '
+' end ) as DBalance,'
+' Sum( case when BalanceDirection=2 then isnull(FirstBalance,0) '
+' else 0 '
+' end '
+' ) as CBalance,'
+' case when sum(case when BalanceDirection=1 then isnull(FirstBalance,0) '
+' else 0 '
+' end )'
+' -Sum( case when BalanceDirection=2 then isnull(FirstBalance,0) '
+' else 0 '
+' end '
+' ) >0 then 1 '
+' when sum(case when BalanceDirection=1 then isnull(FirstBalance,0) '
+' else 0 '
+' end )'
+' -Sum( case when BalanceDirection=2 then isnull(FirstBalance,0) '
+' else 0 '
+' end '
+' )<0 then 2 end as BalanceDirection,'
+' sum(case when BalanceDirection=1 then isnull(FirstfBalance,0) '
+' else 0 '
+' end ) as FDBalance,'
+' Sum( case when BalanceDirection=2 then isnull(FirstfBalance,0) '
+' else 0 '
+' end '
+' ) as FCBalalnce '
// +' sum(isnull(FirstfBalance,0)) as fFirstBalance '
+' from Gl_AccountSubjectBalance t1 '
+' join Gl_AccountSubject t2 on t1.kmid=t2.kmid '
+' and kmlevel='+inttostr(kmlevel+1)
+' and kmCode like '+quotedstr(kmCode+'%'),0);
sqltext:='update Gl_AccountSubjectBalance '
+' set FirstBalance=abs('+AdoQry1.fieldbyname('DBalance').asstring+'-('+AdoQry1.fieldbyname('CBalance').asstring+')),'
+' FirstfBalance=abs('+AdoQry1.fieldbyname('DBalance').asstring+'-('+AdoQry1.fieldbyname('CBalance').asstring+'))/FCurrencyRate, '
+' BalanceDirection = '+IIFString(AdoQry1.fieldbyname('BalanceDirection').AsString='','BalanceDirection',AdoQry1.fieldbyname('BalanceDirection').AsString)
+' where kmid='+inttostr(kmid);
Executesql(AdoQry1,sqltext,1);
AdoQry.Next;
end;
end;
finally
AdoQry.Free;
AdoQry1.Free;
end;
end;
function TFrm_Gl_Enter_StartUseAccount.gatherlowlevel:boolean;
var sqltext:string;
begin
Result:=False;
sqltext:='select * from Gl_AccountSubjectBalance'
+' where exists(select * from Gl_AccountSubject where Gl_AccountSubjectBalance.kmid=Gl_AccountSubject.kmid and Gl_AccountSubject.kmlevel=1 and endkm<>1)';
Executesql(AdoQry_tmp,sqltext,0) ;
while not AdoQry_tmp.Eof do
begin
sumnext(AdoQry_tmp.fieldbyname('kmid').asinteger);
AdoQry_tmp.Next;
end;
Result:=True;
end;
function TFrm_Gl_Enter_StartUseAccount.isBalance:boolean;
var sqltext:string;
yue1,yue2:double;
Balance10,Balance11:double;
Balance20,Balance21:double;
Balance30,Balance31:double;
Balance40,Balance41:double;
Balance50,Balance51:double;
conclusion:string;
begin
Result := False;
gatherlowlevel;
conclusion:='';
//------------------------------------------------------------------------
//--资产类借贷方
SqlText := ' Select JAmount=Sum(Case When BalanceDirection=1 And KmProperty=1 Then FirstBalance '
+' When BalanceDirection=2 And KmProperty=1 Then -FirstBalance '
+' When BalanceDirection=2 And KmProperty=2 Then -FirstBalance '
+' When BalanceDirection=1 And KmProperty=2 Then FirstBalance '
+ ' end ) '
+' From Gl_AccountSubjectBalance '
+' Join Gl_AccountSubject ON Gl_AccountSubjectBalance.KMID=Gl_AccountSubject.KMId '
+' where Gl_AccountSubjectBalance.kmid in (Select KmID '
+' From Gl_AccountSubject '
+' Where endkm=1 And kmType in (1)) ';
ExecuteSql(AdoQry_Tmp,SqlText,0);
Balance10 := AdoQry_Tmp.fieldbyname('JAmount').AsFloat;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -