📄 ap_checkout.pas
字号:
end;
AdoQry_Tmp.Connection.beginTrans ;
Screen.Cursor:=CrSQLWait;
try
deleteApsum; //删除指定月份的月度应付款情况汇总表ApSum 的资料;
DeletezOrUpdateApParam; //更新或删除应付账款管理参数ApParam的结帐标记;
deleteApBalance; //删除指定月份的应付帐款期初余额表ApBalance 的资料;
AdoQry_Tmp.Connection.CommitTrans ;
DispInfo('取消结帐成功!',3);
Screen.Cursor:=crDefault ;
DispApcheckMonth;
btn_ok.enabled:=True;
btn_CancelApCheckout.enabled:=False;
except
AdoQry_Tmp.Connection.RollBackTrans ;
DispInfo('取消结帐失败!',1);
Screen.Cursor:=crDefault ;
abort;
end;
end;
end;
function TFrm_Ap_Checkout.nextMonth(Month: string): string; //获取后一个月份;
var
fYear:string;
fMonth:string;
begin
if length(Trim(Month))=7 then
begin
fYear:=copy(Trim(Month),1,4);
fMonth:=copy(Trim(Month),6,7);
if fMonth='12' then
begin
fMonth:='01';
fYear:=inttostr(strtoint(fYear)+1);
end
else
begin
if fMonth>='09' then
fMonth:=inttostr(strtoint(fMonth)+1)
else
fMonth:='0'+''+inttostr(strtoint(fMonth)+1)+'';
end;
Result:=''+fYear+''+'.'+''+fMonth+'';
end
else
begin
DispInfo('月份非法!',1);
abort;
end;
end;
function TFrm_Ap_Checkout.preMonth(Month: string): string; //获取前一个月份;
var
fYear:string;
fMonth:string;
begin
if length(Trim(Month))=7 then
begin
fYear:=copy(Trim(Month),1,4);
fMonth:=copy(Trim(Month),6,7);
if fMonth='01' then
begin
fMonth:='12';
fYear:=inttostr(strtoint(fYear)-1);
end
else
begin
if (fMonth='11') or (fMonth='12') then
fMonth:=inttostr(strtoint(fMonth)-1)
else
fMonth:='0'+''+inttostr(strtoint(fMonth)-1)+'';
end;
Result:=''+fYear+''+'.'+''+fMonth+'';
end
else
begin
DispInfo('月份非法!',1);
abort;
end;
end;
procedure TFrm_Ap_Checkout.FormClose(Sender: TObject;
var Action: TCloseAction);
begin
inherited;
action:=cafree;
end;
function TFrm_Ap_Checkout.ApCheckInout(Month:string): Boolean;
var
i,j:integer;
begin
i:=0;
j:=0;
with AdoQry_Tmp do
begin
Close;
sql.clear;
sql.Add('select ApInvoiceno '+
' from ApInvoice '+
' where convert(varchAr(7),ApInvoiceInputDate,102)='+Month+'');
open;
i:=AdoQry_Tmp.recordCount;
Close;
sql.clear;
sql.Add('select PayBillNo '+
' from PayJournal '+
' where convert(varchAr(7),PayDate,102)='+Month+'');
open;
j:=AdoQry_Tmp.recordCount;
Close;
end;
if (i>0) or (j>0) then
Result:=True
else
Result:=False;
end;
procedure TFrm_Ap_Checkout.DispApcheckMonth; //显示结帐月;
begin
With AdoQry_Tmp do
begin
Close;
sql.clear;
sql.Add('select ApParamValuec '+
' from ApParam '+
' where ApParamCode=''clsperiod''');
open;
curApMonth:=AdoQry_Tmp.fieldbyname('ApParamValuec').asstring;
Close;
end;
btn_CancelApCheckout.Enabled :=(curApMonth<>'');
if curApMonth<>'' then
begin
Lbl_PApcheckMonth.Caption:=curApMonth;
Lbl_CApcheckMonth.Caption:=nextMonth(Trim(curApMonth));
end
else
begin
Lbl_PApcheckMonth.Caption:='';
Lbl_CApcheckMonth.Caption:=formatdatetime('yyyy.mm',now);
end;
end;
procedure TFrm_Ap_Checkout.UpdateApBalance; //更新应付帐款期初余额表ApBalance;
begin
with AdoQry_Main do
begin
Close;
sql.text:=' insert into ApBalance '+
' select '+''+nextMonth(Trim(Lbl_CApcheckMonth.Caption))+''+','+
' VendorCode ,'+
' InvoiceBalance,'+
' noInviceBalance '+
' from ApBalance '+
' where ApBalance.ApBalanceMonth='''+Trim(Lbl_CApcheckMonth.Caption)+''' ';
execsql;
Close;
sql.text:=' insert into ApBalance '+
' select '+''+nextMonth(Trim(Lbl_CApcheckMonth.Caption))+''+','+
' Apsum.VendorCode ,'+
' 0,'+
' 0 '+
' from Apsum '+
' where Apsum.ApsumMonth='+quotedstr(Trim(Lbl_CApcheckMonth.Caption))+
' and Apsum.VendorCode not in (select VendorCode from ApBalance '+
' where ApBalanceMonth='+QuotedStr(nextMonth(Trim(Lbl_CApcheckMonth.Caption)))+')';
execsql;
Close;
sql.clear;
sql.text:=' update ApBalance set InvoiceBalance=isnull(InvoiceBalance,0)+'+
' isnull(Apsum.ApSumInvoiced,0)-(isnull(Apsum.ApSumPayed,0)),'+
' noInviceBalance=isnull(noInviceBalance,0)+'+
' isnull(Apsum.ApSumNoInvoice,0)-(isnull(Apsum.ApSumInvoiced,0)) '+
' from Apsum where Apsum.VendorCode=ApBalance.VendorCode and '+
' Apsum.ApsumMonth='+quotedstr(Trim(Lbl_CApcheckMonth.Caption))+
' and ApBalance.ApBalanceMonth='+
QuotedStr(nextMonth(Trim(Lbl_CApcheckMonth.Caption)));
execsql;
end;
{with AdoQry_Main do
begin
Close;
sql.clear;
sql.Add('select top 0 * from ApBalance ');
open;
with AdoQry_tmp do
begin
Close;
sql.clear;
sql.Add('select VendorCode from Vendor'+
' where VendorCode not in '+
' (select VendorCode from ApSum '+
' where ApSumMonth='''+Trim(Lbl_CApcheckMonth.Caption)+''')');
open;
if not AdoQry_Tmp.Eof then
begin
AdoQry_Tmp.First;
if AdoQry_Main.Active=False then AdoQry_Main.Active :=True;
while not AdoQry_Tmp.eof do
begin
AdoQry_Main.insert;
AdoQry_Main.fieldbyname('ApBalanceMonth').asstring:=nextMonth(Trim(Lbl_CApcheckMonth.Caption));
AdoQry_Main.fieldbyname('VendorCode').asstring:=AdoQry_Tmp.fieldbyname('VendorCode').asstring;
AdoQry_Main.fieldbyname('InvoiceBalance').asfloat:=0.00;
AdoQry_Main.fieldbyname('NoInviceBalance').asfloat:=0.00;
AdoQry_Main.post;
AdoQry_Tmp.Next;
end;
end;
end;
AdoQry_Main.UpdateBatch ;
end;}
end;
procedure TFrm_Ap_Checkout.deleteApBalance; //删除指定月份的应付帐款期初余额表ApBalance 的资料;
begin
with AdoQry_Tmp do
begin
Close;
sql.clear;
sql.Add('delete from ApBalance '+
' where ApBalanceMonth='''+Trim(Lbl_CApcheckMonth.Caption)+'''' );
execsql;
end;
end;
procedure TFrm_Ap_Checkout.deleteApsum; //删除指定月份的月度应付款情况汇总表ApSum 的资料;
begin
with AdoQry_tmp do
begin
Close;
sql.clear;
sql.Add('delete from Apsum '+
' where ApSumMonth='''+Trim(Lbl_PApcheckMonth.Caption)+'''');
execsql;
end;
end;
procedure TFrm_Ap_Checkout.DeletezOrUpdateApParam; //更新或删除应付账款管理参数ApParam的结帐标记;
var
MinApMonth:string;
begin
With AdoQry_Tmp do
begin
Close;
sql.clear;
sql.Add('select min(ApBalanceMonth) as minApBalanceMonth '+
' from ApBalance ');
open;
MinApMonth:=fieldbyname('minApBalanceMonth').asstring;
Close;
end;
if Trim(Lbl_PApcheckMonth.Caption)>=MinApMonth then
begin
with AdoQry_Main do
begin
Close;
sql.clear;
sql.Add('update ApParam '+
' set ApParamValuec='''+preMonth(Trim(Lbl_PApcheckMonth.Caption))+''''+
' where ApParamCode=''clsperiod''');
execsql;
end;
end;
if Trim(Lbl_PApcheckMonth.Caption)<MinApMonth then
begin
with AdoQry_Main do
begin
Close;
sql.clear;
sql.Add('delete from ApParam '+
' where (ApParamValuec='''+preMonth(Trim(Lbl_PApcheckMonth.Caption))+''')'+
' and( ApParamCode=''clsperiod'')');
execsql;
end;
DispInfo('已经不能再取消结帐了',3);
end;
end;
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -