📄 ap_invoice.pas
字号:
begin
if Assigned(TMaskEdit(Controls[i]).OnExit) then
TMaskEdit(Controls[i]).OnExit(Controls[i]);
end
else if Controls[i] is TCombobox then
begin
if Assigned(TCombobox(Controls[i]).OnExit) then
TCombobox(Controls[i]).OnExit(Controls[i]);
end
end;
if AdoQry_Main.IsEmpty then
begin
DispInfo('没有行数据,不能保存!',1);
Abort;
end;
AdoQry_Main.DisableControls ;
AdoQry_Main.First;
while not AdoQry_Main.eof do
begin
if AdoQry_Main.fieldbyname ('InvBillfinchck').asinteger=1 then
K:=K+1;
AdoQry_Main.next;
end;
if k=0 then
begin
DispInfo('没有行数据,不能保存!',1);
Abort;
end;
if not isequal then
begin
DispInfo('单据金额总金额,与发票中(不含税金额)之差超出允许误差范围,不能保存!',1);
//Abort;
exit;
end;
GetExchRate; //得到汇率;
//开始事物提交
if not DbConnect.InTransaction then
DbConnect.beginTrans ;
//DbConnect.beginTrans;
try
If flag=3 then
//删除以前的暂存当前单据;
begin
DeleteApInvoice(PerSaveApInvoiceNo);
UnDeleteInvInBill;
flag:=2;
SaveApInvoiceLog;
SaveApInvoiceLineLog;
flag1:=1;
end;
{ //删除当前单据
if flag=4 then
begin
//判断此发票是否为暂存票据;
if not isperSaveBillNo(Trim(Edt_ApInvoiceNo.text)) then
begin
UnUpdateCurrentAp;
end;
UnDeleteInvInBill;
DeleteApInvoice(Trim(Edt_ApInvoiceNo.text));
SaveApInvoiceLog;
SaveApInvoiceLineLog;
end;}
SaveApInvoice;
InputInvInBillNoToApInvoice;
UpdateInvInBill;
SaveApInvoiceLog;
SaveApInvoiceLineLog;
if (flag<>4) and ( IsPrePay <0.00) then
//如果有预付款;
begin
if strtofloat(Trim(Edt_ApInvoiceNoTax.text)) >=abs(IsPrePay) then
Pay:=abs(IsPrePay)
else
Pay:=strtofloat(Trim(Edt_ApInvoiceNoTax.text));
//设置付款匹配标志(预付款时);
if abs(IsPrePay)>=strtofloat(Trim(Edt_ApInvoiceNoTax.text)) then
j:=0
else
j:=1;
MatchPay(Trim(ExtEdt_VendorCode.text),Pay); //用发票匹配预付款;
UpdateApInvoiceApPayedAmount(Pay); //修改付款匹配金额(预付款时);
UpdateApInvoiceApPayFlag(j); //修改付款匹配标志(预付款时);
//updateCurrentApp; //修改一张付款票据时,在当前应付款CurrentAp表中修改相应数据;
UpdateCurrentAp;
end
else
UpdateCurrentAp;
DbConnect.CommitTrans;
if (Trim(edit2.text)<>'') then
begin
end
else
begin
edit2.text:='';
end;
DispInfo('存盘成功!',3);
flag:=0;
AdoQry_Main.EnableControls ;
except
DbConnect.RollBackTrans;
DispInfo('存盘失败!',1);
Abort; //停止
end;
GetFieldValue(Trim(Edt_ApInvoiceNo.text));
AdoQry_Main.EnableControls ;
ReadOnly(2);
TLBtn_Save.Enabled:=False;
TLBtn_PerSave.Enabled:=False;
TLBtn_New.Enabled:=True;
TLBtn_Delete.Enabled:=True;
TLBtn_Qury.Enabled:=True;
TlBtn_Cancel.Enabled:=False;
Pnl_Hint.Caption :='';
flag1:=0;
end;
procedure TFrm_Ap_Invoice.TlBtn_DeleteClick(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(Medt_ApInvoiceInputDate.text),1,7)) then
begin
Yearstr:=copy(Trim(Medt_ApInvoiceInputDate.text),1,4);
if copy(Trim(Medt_ApInvoiceInputDate.text),6,1)='0' then
Monthstr:=copy(Trim(Medt_ApInvoiceInputDate.text),7,1)
else
Monthstr:=copy(Trim(Medt_ApInvoiceInputDate.text),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 ApInvoiceid'
+' from ApInvoice '
+' where ApInvoiceNo='''+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_New.enabled:=True;
TLBtn_Save.enabled:=False;
TlBtn_Delete.enabled:=False;
TlBtn_Qury.Enabled:=True;
// TlBtn_Cancel.Enabled:=False;
clearedit;
ReadOnly(2);
end;
end;
end;
procedure TFrm_Ap_Invoice.Edt_VendorCodeExit(Sender: TObject);
var
I:Integer;
begin
inherited;
with AdoQry_Main do
begin
Close;
sql.clear;
sql.Add('select InvInBill.WhCode ,'+
' Warehouse.WHName ,'+
' InvInBill.InvBillNo , '+
' InvInBillLine.InvBillNoTaxAmountc as InvBillNoTaxAmount,'+
' InvInBill.InvBillFinChck '+
' from InvInBill left join Warehouse '+
' on InvInBill.WhCode=Warehouse.WhCode '+
' left join InvInBillLine '+
' on InvInBill.InvBillid=InvInBillLine.InvBillid '+
' where InvInBill.VendorCode='''+ExtEdt_VendorCode.text+''''+
' and InvInBill.InvBillFinChck=0');
open;
i:=AdoQry_Main.recordCount;
Pnl_Hint.Caption :='提示:入库单的行数:'+inttostr(i);
Close;
end;
end;
procedure TFrm_Ap_Invoice.FormClose(Sender: TObject;var Action: TCloseAction);
begin
inherited;
//if (TlBtn_PerSave.enabled=True) or (TlBtn_Save.enabled=True) then
if flag=1 then
begin
if not AdoQry_Main.IsEmpty then
begin
if DispInfo('要保存当前资料吗?',2)='y' then
begin
//if TlBtn_PerSave.enabled=True then
// TlBtn_PerSaveclick(sender);
if TlBtn_Save.enabled=True then
TlBtn_Saveclick(sender);
end
else
Action:=cafree;
end
else
Action:=cafree;
end
else
Action:=cafree;
end;
procedure TFrm_Ap_Invoice.GetFieldValue(InvoiceNo: string);
begin
flag1:=1;
if Trim(InvoiceNo)<>''then
with AdoQry_Tmp do
begin
Close;
sql.clear;
sql.Add('select ApInvoice.*,'+
' Vendor.VendorName, '+
' Vendor.VendorTaxRate_Percent , '+
' Currency.CurrencyName ,'+
' Employee.EmployeeName '+
'from ApInvoice left join Vendor '+
' on ApInvoice.VendorCode= Vendor.VendorCode '+
' left join Currency '+
' on ApInvoice.CurrencyCode=Currency.CurrencyCode '+
' left join Employee '+
' on ApInvoice.EmployeeCode=Employee.EmployeeCode '+
'where ApInvoice.ApInvoiceNo='''+InvoiceNo+''' ');
open;
//把得到的数据显示出来
CmBx_ApInvoiceType.ItemIndex := fieldbyname('ApInvoiceType').asinteger;
{case fieldbyname('ApInvoiceType').asinteger of
0: CmBx_ApInvoiceType.text:='发票';
1: CmBx_ApInvoiceType.text:='收据';
//2: CmBx_ApInvoiceType.text:='暂存';
end;}
Edt_ApInvoiceNo.text:=fieldbyname('ApInvoiceNo').asstring;
Medt_ApInvoiceDate.text:=formatdatetime('yyyy.mm.dd',fieldbyname('ApInvoiceDate').asdatetime);
Lbl_EmployeeCode.text:=fieldbyname('EmployeeCode').asstring;
Lbl_EmployeeName.text:=fieldbyname('EmployeeName').asstring;
Medt_ApInvoiceInputDate.text:=formatdatetime('yyyy.mm.dd',fieldbyname('ApInvoiceInputDate').asdatetime);
ExtEdt_VendorCode.text:=fieldbyname('VendorCode').asstring;
Lbl_VendorName.text:=fieldbyname('VendorName').asstring;
Lbl_CurrencyCode.text:=fieldbyname('CurrencyCode').asstring;
Lbl_CurrencyName.text:=fieldbyname('CurrencyName').asstring;
Edt_ApInvoiceAmount.text:=fieldbyname('ApInvoiceAmount').asstring;
Edt_ApInvoiceTax.text:=formatfloat('0.##',fieldbyname('ApInvoiceTax').asfloat);
Edt_ApInvoiceNoTax.text:=floattostr(fieldbyname('ApInvoiceAmount').asfloat-fieldbyname('ApInvoiceTax').asfloat);
Lbl_TaxRate_Percent.text:=inttostr(fieldbyname('VendorTaxRate_Percent').asinteger);
Edt_ApInvoiceRemArk.text:=fieldbyname('ApInvoiceRemArk').asstring;
AdoQry_TMP.Close;
end;
//根据发票号得到相应的入库单号
if not isperSaveBillNo(InvoiceNo) then
begin
with AdoQry_Main do
begin
Close;
sql.clear;
sql.Add('select DISTINCT InvInBill.WhCode+'' ''+ Warehouse.WHName as whCodeName ,'+
' InvInBill.InvBillid as InvBillid ,'+
' InvInBill.InvBillDate,'+
' InvInBill.InvBillNo, '+
' sum(isnull(InvInBillLine.InvBillNoTaxAmountc,0)) as InvBillNoTaxAmount ,'+
' InvInBill.InvBillFinChck '+
' from ApInvoice left join ApInvoiceLine '+
' on ApInvoice.ApInvoiceId=ApInvoiceLine.ApInvoiceId '+
' left join InvInBill '+
' on ApInvoiceLine.InvBillId=InvInBill.InvBillId '+
' left join Warehouse '+
' on InvInBill.WhCode=Warehouse.WhCode '+
' left join InvInBillLine '+
' on InvInBill.InvBillid=InvInBillLine.InvBillid '+
'where ApInvoice.ApInvoiceNo='''+InvoiceNo+''''+
' and InvInBill.InvBillFinChck=1 '+
// ' and InvInBill.realBillflag=1 ' +
' group by InvInBill.WhCode+'' ''+ Warehouse.WHName ,InvInBill.InvBillid,InvInBill.InvBillDate,InvInBill.InvBillNo,InvInBill.VendorCode,InvInBill.InvBillFinChck ');
open;
Label18.Caption:='0';
Listbox1.clear;
tlbtn_look.enabled:=(AdoQry_Main.recordCount>0);
if AdoQry_Main.recordCount>0 then
begin
Pnl_Hint.Caption:='提示:入库单的行数:'+Inttostr(AdoQry_Main.recordCount);
AdoQry_Main.First;
while not AdoQry_Main.eof do
begin
inputListbox;
AdoQry_Main.next;
end;
end
else
Pnl_Hint.Caption:='提示:没有入库单';
end;
end
else
begin
GetPerSaveInvInBill(Trim(InvoiceNo));
end;
end;
procedure TFrm_Ap_Invoice.TlBtn_QuryClick(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
Label18.Caption:='0';
Listbox1.clear;
GetFieldValue(Tmp_ApInvoiceNo);
TlBtn_Delete.Enabled:=Edt_ApInvoiceNo.text<>'';
end
end;
procedure TFrm_Ap_Invoice.FormCreate(Sender: TObject);
begin
inherited;
Lc_CurrApInvoiceId:=0;
ErrRange:=0;
TlBtn_New.Enabled:=True;
TlBtn_Qury.Enabled:=True;
TlBtn_Delete.Enabled:=False;
TlBtn_Cancel.Enabled:=False;
TlBtn_Look.Enabled:=False;
end;
procedure TFrm_Ap_Invoice.Act_NewExecute(Sender: TObject);
begin
inherited;
TlBtn_New.enabled:=True;
end;
procedure TFrm_Ap_Invoice.Act_DeleteExecute(Sender: TObject);
begin
inherited;
TlBtn_Delete.enabled:=True;
end;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -