📄 ap_invoicecancel.pas
字号:
' '''+Trim(Lbl_ApInvoiceRemArk.Caption)+''') '+
'SELECT @@IDENTITY AS CurrlogIdentity '+
'');
open;
if not eof then
begin
//取得存盘后的ID
Lc_CurrApInvoicelogId:=fieldbyname('CurrlogIdentity').AsInteger;
end;
Close;
end;
end;
procedure TFrm_Ap_InvoiceCancel.SaveApInvoiceLog;
var
ApInvoiceId1:String ; // 发票ID;
ApInvoicelogId:string; //日志ID;
begin
ApInvoiceId1:=IntToStr(Lc_CurrApInvoiceId);
ApInvoicelogId:=IntToStr(Lc_CurrApInvoicelogId);
AdoQry_Main.First;
while not AdoQry_Main.Eof do
begin
if AdoQry_Main.fieldbyname('InvBillFinChck').asinteger=1 then
begin
//如果CHECED,则得到入库单的ID
with AdoQry_Tmp do
begin
Close;
Sql.clear ;
Sql.Add('Select InvBillId '+
'from InvInBill '+
'where InvBillNo='''+AdoQry_Main.fieldbyname('InvBillNo').asstring+''' '+
' And WHCode='''+GetCode(Trim(AdoQry_Main.fieldbyname('WHCodeName').asstring))+''' ');
open;
end;
if not AdoQry_Tmp.eof then
begin
//已经查到了入库单的ID
with AdoQuery1
do
begin
Close;
sql.clear;
sql.Add('insert into ApInvoiceLineLog '+
' (ApInvoiceId, '+
' InvBillId) '+
'Values '+
' ('+ApInvoiceId1+', '+
' '+IntToStr(AdoQry_Tmp.fieldbyname('InvBillId').AsInteger)+')');
execsql;
end;
end;
end;
AdoQry_Main.next;
end;
end;
procedure TFrm_Ap_InvoiceCancel.UnDeleteInvInBill;
begin
AdoQry_Main.First;
while not AdoQry_Main.Eof do
begin
if AdoQry_Main.fieldbyname('InvBillFinChck').asinteger=1 then
begin
with AdoQry_Tmp do
begin
Close;
sql.clear;
sql.Add('update InvInBill '+
'set InvBillFinChck=0 '+
'where InvBillNo='''+AdoQry_Main.fieldbyname('InvBillNo').asstring+''' '+
' And VendorCode='''+Trim(lbl_VendorCode.Caption)+''' '+
' And WHCode='''+GetCode(Trim(AdoQry_Main.fieldbyname('WHCodeName').asstring))+''' ');
ExecSql;
end;
end;
AdoQry_Main.next;
end;
end;
function TFrm_Ap_InvoiceCancel.ApCheckout(Month: String): Boolean;
var
str:string;
begin
With AdoQry_Tmp do
begin
Close;
sql.clear;
sql.Add('select ApParamValuec '+
' from ApParam '+
' where ApParamCode=''clsperiod''');
open;
str:=fieldbyname('ApParamValuec').asstring;
if str<>'' then
begin
if Month>str then
Result:=False
else
Result:=True;
end
else
Result:=False;
end;
end;
procedure TFrm_Ap_InvoiceCancel.UpdateCurrentAp;
var
Total:double;
sqlstr:string;
begin
//得到去掉税额的金额
Total:=strtofloat((lbl_ApInvoiceAmount.Caption))-strtofloat((lbl_ApInvoiceTax.Caption));
//更新当前应付款
sqlstr:='update CurrentAp '+
'set ApInvoiced=ApInvoiced+'+FloatTostr(Total)+', '+
' ApNoInvoice=ApNoInvoice-('+FloatTostr(Total)+') '+
'where CurrentAp.VendorCode='''+Trim(lbl_VendorCode.Caption)+''' ';
with AdoQry_Tmp do
begin
Close;
sql.clear;
sql.Add(sqlstr);
execsql;
end;
end;
procedure TFrm_Ap_InvoiceCancel.UnUpdateCurrentAp;
var
Total:double;
begin
//得到去掉税额的金额
Total:=strtofloat((lbl_ApInvoiceAmount.Caption))-strtofloat((lbl_ApInvoiceTax.Caption));
//更新当前应付款
with AdoQry_Tmp do
begin
Close;
sql.clear;
sql.Add('update CurrentAp '+
'set ApInvoiced=ApInvoiced-('+FloatTostr(Total)+'), '+
' ApNoInvoice=ApNoInvoice+'+FloatTostr(Total)+' '+
'where CurrentAp.VendorCode='''+Trim(lbl_VendorCode.Caption)+''' ');
execsql;
end;
end;
procedure TFrm_Ap_InvoiceCancel.DeleteApInvoice(ApInvoiceNo: string);
begin
//删除ApInvoiceline;
with AdoQry_Tmp do
begin
Close;
sql.clear;
sql.Add('delete ApInvoiceline '+
'from ApInvoiceLine left join ApInvoice '+
' on ApInvoice.ApInvoiceId=ApInvoiceLine.ApInvoiceId');
sql.Add('where ApInvoice.ApInvoiceNo='''+ApInvoiceNo+'''');
execsql;
end;
//删除ApInvoice;
with AdoQry_Tmp do
begin
Close;
sql.clear;
sql.Add('delete from ApInvoice ');
sql.Add('where ApInvoice.ApInvoiceNo='''+ApInvoiceNo+'''');
execsql;
end;
end;
procedure TFrm_Ap_InvoiceCancel.clearedit;
begin
Edt_ApInvoiceNo.text:='';
Lbl_ApInvoiceDate.Caption:='';
Lbl_EmployeeCode.Caption:='';
Lbl_EmployeeName.Caption:='';
lbl_ApInvoiceInputDate.Caption:='';
Lbl_TaxRate_Percent.Caption:='';
Lbl_ApInvoiceType.Caption:='';
lbl_VendorCode.Caption:='';
Lbl_VendorName.Caption:='';
Lbl_CurrencyCode.Caption:='';
Lbl_CurrencyName.Caption:='';
lbl_ApInvoiceAmount.Caption:='0';
lbl_ApInvoiceTax.Caption:='0';
Lbl_ApInvoiceRemArk.Caption:='';
lbl_ApInvoiceNoTax.Caption:='0';
AdoQry_Main.Close;
end;
procedure TFrm_Ap_InvoiceCancel.Edt_ApInvoiceNoExit(Sender: TObject);
begin
inherited;
if SlaveCodeUsable(Trim(Edt_ApInvoiceNo.text)) then
begin
GetFieldValue(Trim(Edt_ApInvoiceNo.text));
//LJ,取消按钮有效
Act_Cancel.Enabled:=True;
Tlbtn_Cancel.Enabled:=True;
end
else
begin
//LJ,取消按钮无效
Act_Cancel.Enabled:=False;
Tlbtn_Cancel.Enabled:=False;
DispInfo('请输入代码没找到!',1);
TWinControl(Sender).SetFocus;
Abort;
end;
end;
function TFrm_Ap_InvoiceCancel.SlaveCodeUsable(
R_ItemCode: String): Boolean;
var
T_Count:integer;
T_Sql:string;
begin
T_Sql:=
'Select Count(*) as RecordCount '+
' from ApInvoice '+
'where ApInvoiceNo='''+R_ItemCode+''' ';
with AdoQry_Tmp do
begin
Close;
SQL.clear;
SQL.Add(T_Sql);
open;
T_Count:=fieldbyname('RecordCount').AsInteger;
Close;
end;
if T_Count>0 then Result:=True
else Result:=False;
end;
procedure TFrm_Ap_InvoiceCancel.InitForm(AdoConnection: TAdoConnection);
begin
inherited;
flag:=0;
SetDBConnect(AdoConnection);
AdoQry_Main.Connection:=AdoConnection;
AdoQuery1.Connection := AdoConnection;
With AdoQry_Tmp do
begin
Close;
sql.clear;
sql.Add('select ApParamValuec '+
' from ApParam '+
' where ApParamCode=''clsperiod''');
open;
curApMonth:=fieldbyname('ApParamValuec').asstring;
Close;
end;
With AdoQry_Tmp do
begin
Close;
sql.clear;
sql.Add('select VendorTaxRate_Percent'+
' from Vendor '+
' where VendorCode='''+Trim(lbl_VendorCode.Caption)+'''');
open;
TaxRate_Percent:=fieldbyname('VendorTaxRate_Percent').asfloat;
Close;
end;
clearedit;
TlBtn_Cancel.enabled:=False;
end;
procedure TFrm_Ap_InvoiceCancel.Act_LocateExecute(Sender: TObject);
var
Tmp_ApInvoiceNo:String;
begin
inherited;
Tmp_ApInvoiceNo:='';
//取得发票号码
Frm_Ap_Invoice_Select:=TFrm_Ap_Invoice_Select.Create(self);
Frm_Ap_Invoice_Select.InitForm(AdoQry_tmp.Connection);
Frm_Ap_Invoice_Select.ShowModal;
if Frm_Ap_Invoice_Select.ModalResult=mroK then
begin
Tmp_ApInvoiceNo:=Frm_Ap_Invoice_Select.InvoiceNo;
end;
Frm_Ap_Invoice_Select.Release;
//根据取得的发票号码更新数据
if Tmp_ApInvoiceNo<>'' then
begin
i:=0;
TlBtn_Cancel.enabled:=True;
Label18.Caption:='0';
Listbox1.clear;
GetFieldValue(Tmp_ApInvoiceNo);
i:=1;
ControlBar.setfocus;
end;
end;
procedure TFrm_Ap_InvoiceCancel.Act_CancelExecute(Sender: TObject);
var
Yearstr,Monthstr:string;
begin
{if flag=1 then
abort;}
if activecontrol.Name='Edt_ApInvoiceTax' then
abort;
inherited;
//flag:=2;
if ApCheckout(copy(Trim(lbl_ApInvoiceInputDate.Caption),1,7)) then
begin
Yearstr:=copy(Trim(lbl_ApInvoiceInputDate.Caption),1,4);
if copy(Trim(lbl_ApInvoiceInputDate.Caption),6,1)='0' then
Monthstr:=copy(Trim(lbl_ApInvoiceInputDate.Caption),7,1)
else
Monthstr:=copy(Trim(lbl_ApInvoiceInputDate.Caption),6,2);
DispInfo(Yearstr+'年'+Monthstr+'月已经结账,不能删除此张发票!',3) ;
abort;
end;
if DispInfo('取消发票匹配吗!',2)='n' then
abort
else
begin
with AdoQry_Tmp do
begin
Close;
sql.clear;
sql.Add('select ApInvoiceNo'
+' from ApInvoice '
+' where ApInvoiceNo='''+Trim(Edt_ApInvoiceNo.text)+''''
+' and ApPayFlag in (1,0)');
Prepared;
open;
end;
if not AdoQry_Tmp.Isempty then
begin
DispInfo('此发票付款,不能删除!',1);
Abort;
end
else
begin
if not DbConnect.InTransaction then
DbConnect.beginTrans ;
try
//判断此发票是否为暂存票据;
if not isperSaveBillNo(Trim(Edt_ApInvoiceNo.text)) then
begin
//UnDeleteInvInBill;
{if IsPrePay <0.00 then
//如果有预付款;
UnUpdateCurrentApP
else}
UnUpdateCurrentAp;
end;
UnDeleteInvInBill;
DeleteApInvoice(Trim(Edt_ApInvoiceNo.text));
SaveApInvoiceLog;
SaveApInvoiceLineLog;
DbConnect.CommitTrans;
DispInfo('取消匹配成功!',3);
//flag:=0;
Listbox1.clear;
Label18.Caption:='0';
Lbl_Diff.Caption:='0';
Pnl_Hint.Caption:='';
except
DbConnect.RollBackTrans ;
DispInfo('取消匹配失败!',1);
abort;
end;
TlBtn_Cancel.Enabled:=False;
clearedit;
//ReadOnly(2);
end;
end;
end;
procedure TFrm_Ap_InvoiceCancel.Edt_ApInvoiceNoKeyDown(Sender: TObject;
var Key: Word; Shift: TShiftState);
begin
inherited;
{ if Key=120 then
begin
Frm_Sys_Hint:=TFrm_Sys_Hint.Create(nil);
Frm_Sys_Hint.InitForm(DBConnect,
'Select ApInvoiceno as ''票据号'' from ApInvoice'
);
if Frm_Sys_Hint.ShowModal=mrOk then
TEdit(Sender).Text:=Frm_Sys_Hint.GetValueByFieldIndex(0);
Frm_Sys_Hint.Release;
end;}
end;
function TFrm_Ap_InvoiceCancel.PickApInvoiceNo(InitCode: String): String;
begin
Result:=GetCodeHint(
AdoQry_Tmp,
'ApInvoiceInputDate','记帐日期',
'ApInvoiceNo','应付票据号',
'ApInvoice',InitCode,'');
end;
procedure TFrm_Ap_InvoiceCancel.Action4Execute(Sender: TObject);
begin
inherited;
if ActiveControl.Name='Edt_ApInvoiceNo' then
begin
Edt_ApInvoiceNo.Text:=PickApInvoiceNo(Edt_ApInvoiceNo.Text);
Edt_ApInvoiceNo.SetFocus;
end;
end;
procedure TFrm_Ap_InvoiceCancel.FormClose(Sender: TObject;
var Action: TCloseAction);
begin
inherited;
Action:=caFree;
end;
procedure TFrm_Ap_InvoiceCancel.FormActivate(Sender: TObject);
begin
inherited;
//Act_Cancel.Enabled:=False;
end;
procedure TFrm_Ap_InvoiceCancel.AdoQry_MainBeforeInsert(DataSet: TDataSet);
begin
inherited;
abort;
end;
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -