📄 main.pas
字号:
result:=0;
ip:=StrToIntDef(CurrPeroid, 0);
IF D1>D2 THEN iPeriod:=ip;
IF (D1<D2)AND(D1>D3) THEN iPeriod:=ip-1;
IF D1<D3 THEN iPeriod:=ip-2;
result:=iPeriod;
END;
VAR
Date1, Date2, StartDate, EndDate1, UseD1, UseD2:STRING;
sSQL, AKmbh, AKmmc:STRING;
iPeriod, k, v, Days:integer;
m1, m2, StartYe, JS1, JS2, YE1, crate, clx:Currency;
bend:Boolean;
fsCount:integer; //指定时间内的发生笔数
BEGIN
CurrPeroid:=IntToStr(FDM.GetMaxPeriod);
StartDate:=FormatDateTime('yyyy-mm-dd', edtBeginDate.Date);
EndDate1:=FormatDateTime('yyyy-mm-dd', edtEndDate.Date);
crate:=GetRate(StartDate)/365.00;
sSQL:='select * from ufsystem..UA_Period '
+' where cAcc_id='+QuotedStr(CurrAccID)+' and iYear='+CurrAccYear
+' and iID='+CurrPeroid;
TRY
Screen.Cursor:=crHourGlass;
TruncateTempData;
OpenSQL(FDM.aqTemp, sSQL);
StatProgress.TotalParts:=FDM.aqKm.RecordCount;
StatProgress.Visible:=true;
TRY
IF FDM.aqTemp.RecordCount>0 THEN
BEGIN
Date1:=FormatDateTime('yyyy-mm-dd', FDM.aqTemp.FieldByName('dBegin').AsDateTime);
Date2:=FormatDateTime('yyyy-mm-dd', FDM.aqTemp.FieldByName('dEnd').AsDateTime);
END ELSE
BEGIN
IF CurrPeroid='0' THEN
BEGIN
Date1:=FormatDateTime('yyyy-mm-dd', StartOfAMonth(StrToInt(CurrAccYear), 1));
Date2:=FormatDateTime('yyyy-mm-dd', EndOfAMonth(StrToInt(CurrAccYear), 1));
END ELSE
BEGIN
Date1:=FormatDateTime('yyyy-mm-dd', StartOfAMonth(StrToInt(CurrAccYear), StrToInt(CurrPeroid)));
Date2:=FormatDateTime('yyyy-mm-dd', EndOfAMonth(StrToInt(CurrAccYear), StrToInt(CurrPeroid)));
END;
END;
EXCEPT
Date1:=FormatDateTime('yyyy-mm-dd', StartOfAMonth(StrToInt(CurrAccYear), StrToInt(CurrPeroid)));
Date2:=FormatDateTime('yyyy-mm-dd', EndOfAMonth(StrToInt(CurrAccYear), StrToInt(CurrPeroid)));
END;
FDM.aqTemp.Close;
iPeriod:=GetCanUsePeriod(StrToDate(StartDate), StrToDate(Date1), StrToDate(Date2));
IF iPeriod<=0 THEN
UseD1:=FormatDateTime('yyyy-mm-dd', StartOfAYear(StrToInt(CurrAccYear)))
ELSE
UseD1:=FormatDateTime('yyyy-mm-dd', IncDay(EndOfAMonth(StrToInt(CurrAccYear), iPeriod), 1));
FDM.aqKm.DisableControls;
FDM.aqKm.First;
FOR k:=0 TO FDM.aqKm.RecordCount-1 DO
BEGIN
bend:=FDM.aqKm.FieldByName('末级').AsBoolean;
IF NOT bend THEN
BEGIN
FDM.aqKm.Next;
Continue;
END;
AKmbh:=FDM.aqKm.FieldByName('编码').AsString;
AKmmc:=FDM.aqKm.FieldByName('名称').AsString;
IF AKmbh<>'' THEN
BEGIN
ShowInfo(Stat2, AKmbh+' '+AKmmc);
m1:=GetKmYe(IntToStr(iPeriod), AKmbh); //使用会计期间止的期末余额
m2:=GetKmFss(AKmbh, StrToDate(UseD1), StrToDate(StartDate)); //使用会计期间到起始计息日间的发生
StartYe:=m1+m2; //起始计息日的余额
sSQL:=' SELECT ccode,ino_id, dbill_date, max(iperiod) as iperiod, max(cbill) as cbill,'
+' max(ccheck) as ccheck, max(cbook) as cbook, (sum(mc)- sum(md)) as fs '
+' FROM '+CurrYearDB+'..GL_accvouch '
+' where iflag is null and dbill_date>='+QuotedStr(StartDate)
+' and dbill_date<='+QuotedStr(EndDate1)
+' and ccode in ('+QuotedStr(AKmbh)+')'
+' group by ccode,ino_id, dbill_date '
+' order by ccode,ino_id,dbill_date';
TRY
TRY
OpenSQL(FDM.aqAcc_Voucher, sSQL);
FDM.aqAcc_Voucher.DisableControls;
JS2:=0;
fsCount:=FDM.aqAcc_Voucher.RecordCount;
IF (fsCount>0) THEN //有余额且有发生数 and(StartYe>0.001)
BEGIN
FOR v:=0 TO fsCount DO
BEGIN
IF v=0 THEN
BEGIN
YE1:=StartYe;
UseD1:=StartDate;
END ELSE
BEGIN
YE1:=StartYe+FDM.aqAcc_Voucher.FieldByName('fs').AsCurrency;
UseD1:=UseD2;
END;
IF v=fsCount THEN
BEGIN
UseD2:=EndDate1;
END ELSE
BEGIN
UseD2:=FDM.aqAcc_Voucher.FieldByName('dbill_date').AsString;
END;
Days:=DaysBetween(StrToDate(UseD1), StrToDate(UseD2));
JS1:=YE1*Days;
JS2:=JS2+JS1;
//写表
sSQL:='exec pubs..insert_Acc_Rate_1 '+QuotedStr(AKmbh)+','
+FDM.aqAcc_Voucher.FieldByName('ino_id').AsString+','
+QuotedStr(FDM.aqAcc_Voucher.FieldByName('dbill_date').AsString)+','
+FDM.aqAcc_Voucher.FieldByName('iperiod').AsString+','
+QuotedStr(FDM.aqAcc_Voucher.FieldByName('cbill').AsString)+','
+QuotedStr(FDM.aqAcc_Voucher.FieldByName('ccheck').AsString)+','
+QuotedStr(FDM.aqAcc_Voucher.FieldByName('cbook').AsString)+','
+FDM.aqAcc_Voucher.FieldByName('fs').AsString+','
+CurrToStr(YE1)+','
+CurrToStr(StartYe)+','
+CurrToStr(crate)+','
+CurrToStr(JS2)+','
+CurrToStr(JS2*crate)+','
+QuotedStr(AKmmc);
TRY
IF Abs(JS2)>0.001 THEN
ExecSQL(FDM.aqExec, sSQL);
EXCEPT
MyWarning('写入计息临时数据出错......');
END;
IF v=fsCount THEN Break;
FDM.aqAcc_Voucher.Next;
END; //end of for v
END ELSE //时间内发业务发生
BEGIN
IF StartYe<0.001 THEN
BEGIN
FDM.aqKm.Next;
Continue;
END;
YE1:=StartYe;
Days:=DaysBetween(StrToDate(StartDate), StrToDate(EndDate1));
JS2:=YE1*Days;
//写表
sSQL:='exec pubs..insert_Acc_Rate_1 '+QuotedStr(AKmbh)+','
+'0,'
+QuotedStr(StartDate)+','
+'0,'
+QuotedStr('')+','
+QuotedStr('')+','
+QuotedStr('')+','
+'0,'
+CurrToStr(YE1)+','
+CurrToStr(StartYe)+','
+CurrToStr(crate)+','
+CurrToStr(JS2)+','
+CurrToStr(JS2*crate)+','
+QuotedStr(AKmmc);
TRY
ExecSQL(FDM.aqExec, sSQL);
EXCEPT
MyWarning('写入计息临时数据出错......');
END;
END;
EXCEPT
END;
FINALLY
END;
END; // end of if
FDM.aqKm.Next;
END; // end of for k
//sSQL:='update pubs..acc_rate set lx'
sSQL:='SELECT KeyID as 序号, Kmbh as 科目编码, kmmc as 科目名称, Pzbh as 凭证编号, PzDate as 操作时间, '
+'Peroid as 会计期间, biller as 出纳, checker as 会计, amount as 发生额,'
+'bqye as 本期余额, qcye as 期初余额, rate as 利率, js as 积数, lx as 利息'
+' FROM pubs.dbo.Acc_Rate ';
OpenSQL(FDM.aqRateMx, sSQL);
bRate:=(FDM.aqRateMx.RecordCount>0);
PageRate.ActivePageIndex:=0;
FINALLY
StatProgress.Visible:=false;
FDM.aqKm.EnableControls;
FDM.aqAcc_Voucher.EnableControls;
Screen.Cursor:=crDefault;
END; // end of try
SetButtonStat;
END; // end of procedure
PROCEDURE TfmMain.edtCurrYearChange(Sender:TObject);
BEGIN
IF fsShowing IN Self.FormState THEN exit;
SetDateRang(true);
CurrAccYear:=edtCurrYear.Text;
SetDateRang;
// Self.OpenYearDB;
CurrPeroid:=IntToStr(FDM.GetMaxPeriod);
edtCurrPeriod.Max:=StrToInt(CurrPeroid);
edtCurrPeriod.Value:=edtCurrPeriod.Max;
END;
PROCEDURE TfmMain.SetYearRang;
VAR sSQL:STRING;
BEGIN
sSQL:='select * from '+sUFSYS+'..UA_Account_sub '
+' where cAcc_Id='+QuotedStr(CurrAccID)+' and iYear<>''9999'' and cSub_ID in(''GL'')'
+' order by iYear ';
TRY
OpenSQL(FDM.aqTemp, sSQL);
IF FDM.aqTemp.RecordCount>0 THEN
BEGIN
edtCurrYear.Min:=FDM.aqTemp.FieldByName('iYear').asInteger; //StartOfAYear();
FDM.aqTemp.Last;
edtCurrYear.Max:=FDM.aqTemp.FieldByName('iYear').asInteger; // EndOfAYear();
END;
FINALLY
FDM.aqTemp.Close;
END;
END;
PROCEDURE TfmMain.edtRateKMChange(Sender:TObject);
BEGIN
sRateKM:=trim(edtRateKM.Text);
END;
FUNCTION TfmMain.GetRate(ADate:STRING):Currency;
BEGIN
TRY
{cdsRate.Filtered:=false;
cdsRate.Filter:='RateDate<='+QuotedStr(FormatDateTime('yyyy-mm-dd', ADate));
cdsRate.Filtered:=true; }
cdsRate.Last;
result:=cdsRate.FieldByName('RateRate').AsCurrency;
EXCEPT
result:=0.00;
END;
END;
PROCEDURE TfmMain.edtAccID1Change(Sender:TObject);
VAR s:STRING;
BEGIN
CurrAccID:=Format('%.3d', [StrToInt(edtAccID1.Text)]); //FormatAccID();
TRY
Screen.Cursor:=crHourGlass;
s:=GetConnStr('master', trim(edtDataServer.Text), trim(edtDataPass.Text), trim(edtDataUser.Text));
bLinked:=(ConnectADO(FDM.DBConn, s, 30, false)=1);
IF NOT bLinked THEN
BEGIN
MyWarning('测试连接失败!'#13#10'请重新设置...');
exit;
END;
Self.SetYearRang();
FINALLY
Screen.Cursor:=crDefault;
END;
END;
PROCEDURE TfmMain.edtEndDateChange(Sender:TObject);
BEGIN
IF edtEndDate.Date<edtBeginDate.Date THEN
edtEndDate.Date:=edtBeginDate.Date;
END;
PROCEDURE TfmMain.edtBeginDateChange(Sender:TObject);
BEGIN
IF edtEndDate.Date<edtBeginDate.Date THEN
edtBeginDate.Date:=edtEndDate.Date;
END;
PROCEDURE TfmMain.btnTestLinkClick(Sender:TObject);
VAR
s:STRING;
TestOK:Boolean;
BEGIN
s:=GetConnStr('master', trim(edtDataServer.Text), trim(edtDataPass.Text), trim(edtDataUser.Text));
Test:=TADOConnection.Create(NIL);
TRY
TestOK:=(ConnectADO(Test, s, 30, false)=1);
IF TestOK THEN
MyInformation('测试连接成功...')
ELSE
MyWarning('测试连接失败!'#13#10#13#10'请重新设置...');
FINALLY
Test.Free;
END;
END;
PROCEDURE TfmMain.BtnOpenClick(Sender:TObject);
BEGIN
Self.OpenYearDB(true);
Self.edtCurrYearChange(NIL);
SetButtonStat;
END;
PROCEDURE TfmMain.SetDateRang(bCls:Boolean=false);
BEGIN
IF NOT bCls THEN
BEGIN
edtBeginDate.MaxDate:=EndOfAYear(StrToInt(CurrAccYear));
edtBeginDate.MinDate:=StartOfAYear(StrToInt(CurrAccYear));
END ELSE
BEGIN
edtBeginDate.MaxDate:=EndOfAYear(2100);
edtBeginDate.MinDate:=StartOfAYear(1900);
END;
edtEndDate.MaxDate:=edtBeginDate.MaxDate;
edtEndDate.MinDate:=edtBeginDate.MinDate;
END;
PROCEDURE TfmMain.BtnCascadeClick(Sender:TObject);
VAR sSQL:STRING;
BEGIN
TRY
Screen.Cursor:=crHourGlass;
sSQL:='SELECT Kmbh as 科目编码, max(kmmc) as 科目名称, max(bqye) as 本期余额, sum(amount) as 发生额, '
+' max(js) as 积数, max(lx) as 利息 '
+' FROM pubs.dbo.Acc_Rate '
+' group by Kmbh'
+' order by Kmbh';
OpenSQL(FDM.aqRateHz, sSQL);
PageRate.ActivePageIndex:=1;
FINALLY
Screen.Cursor:=crDefault;
END;
END;
PROCEDURE TfmMain.GridKmDblClick(Sender:TObject);
BEGIN
//locate
END;
PROCEDURE TfmMain.PageRateChange(Sender:TObject);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -