📄 ap_invoice.pas
字号:
//程序功能:采购发票录入及匹配
unit Ap_Invoice;
Interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
Base_Panel, StdCtrls, ActnList, Db, AdODB, ExtCtrls, ComCtrls, ToolWin,
Grids, DBGridEh, Mask, ExtEdit, jpeg, linkedit;
Type
TFrm_Ap_Invoice = Class(TFrm_Base_Panel)
TlBtn_New: TToolButton;
ToolButton2: TToolButton;
TlBtn_Save: TToolButton;
ToolButton4: TToolButton;
TlBtn_Delete: TToolButton;
TlBtn_Qury: TToolButton;
ToolButton8: TToolButton;
TlBtn_Exit: TToolButton;
AdoQry_ApInvoice: TAdoQuery;
DS_AdoQry_Main: TDataSource;
AdoQry_ApInvoiceLine: TAdoQuery;
AdoQry_Main: TAdoQuery;
Panel1: TPanel;
ToolButton1: TToolButton;
TlBtn_Cancel: TToolButton;
ToolButton3: TToolButton;
ToolButton5: TToolButton;
Action4: TAction;
tlbtn_look: TToolButton;
ToolButton7: TToolButton;
Label10: TLabel;
Edit2: TEdit;
Label14: TLabel;
Panel2: TPanel;
DBGridEh1: TDBGridEh;
Panel3: TPanel;
Panel4: TPanel;
Label15: TLabel;
ListBox1: TListBox;
TlBtn_PerSave: TToolButton;
ToolButton9: TToolButton;
AdoQry_MainwhCodeName: TStringField;
AdoQry_MainInvBillid: TBCDField;
AdoQry_MainInvBilldate: TDateTimeField;
AdoQry_MainInvBillno: TStringField;
AdoQry_MainInvBillNoTaxAmount: TBCDField;
AdoQry_MainInvBillfinchck: TIntegerField;
Label17: TLabel;
Lbl_Diff: TLabel;
Label18: TLabel;
Label2: TLabel;
Edt_ApInvoiceNo: TEdit;
Label3: TLabel;
Medt_ApInvoicedate: TMaskEdit;
Label1: TLabel;
CmBx_ApInvoiceType: TComboBox;
Label6: TLabel;
Medt_ApInvoiceInputDate: TMaskEdit;
Label7: TLabel;
ExtEdt_VendorCode: TLinkEdit;
Lbl_VendorName: TEdit;
Label16: TLabel;
Lbl_TaxRate_Percent: TEdit;
Label9: TLabel;
Lbl_CurrencyCode: TEdit;
Lbl_CurrencyName: TEdit;
Lbl_Notax: TLabel;
Edt_ApInvoiceNoTax: TEdit;
Label12: TLabel;
Edt_ApInvoiceTax: TEdit;
Label11: TLabel;
Edt_ApInvoiceAmount: TEdit;
Label4: TLabel;
Lbl_EmployeeCode: TEdit;
Lbl_EmployeeName: TEdit;
Label13: TLabel;
Edt_ApInvoiceRemArk: TEdit;
procedure TlBtn_NewClick(Sender: TObject);
procedure Edt_ApInvoiceNoExit(Sender: TObject);
procedure TlBtn_SaveClick(Sender: TObject);
procedure TlBtn_DeleteClick(Sender: TObject);
procedure Edt_VendorCodeExit(Sender: TObject);
procedure FormClose(Sender: TObject; var Action: TCloseAction);
procedure TlBtn_QuryClick(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure Act_NewExecute(Sender: TObject);
procedure Act_DeleteExecute(Sender: TObject);
procedure Act_LocateExecute(Sender: TObject);
procedure FormShow(Sender: TObject);
procedure GetCurrencyName(Sender: TObject);
procedure Edt_ApInvoiceTaxExit(Sender: TObject);
procedure Act_CancelExecute(Sender: TObject);
procedure VendorCodeCheck(Sender: TObject);
procedure Edt_ApInvoiceAmountExit(Sender: TObject);
procedure Edt_ApInvoiceNoTaxExit(Sender: TObject);
procedure DBGridEh1DblClick(Sender: TObject);
procedure Action4Execute(Sender: TObject);
procedure ExtEdt_VendorCode1Exit(Sender: TObject);
procedure tlbtn_lookClick(Sender: TObject);
procedure DBGridEh1Enter(Sender: TObject);
procedure FormKeyPress(Sender: TObject; var Key: ChAr);
procedure AdoQry_MainInvBillFinChckChange(Sender: TField);
procedure Edit2Exit(Sender: TObject);
procedure AdoQry_MainBeforeOpen(DataSet: TDataSet);
procedure DBGridEh1MouseUp(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
procedure TlBtn_PerSaveClick(Sender: TObject);
procedure Edt_ApInvoiceNoTaxChange(Sender: TObject);
procedure Act_ModifyExecute(Sender: TObject);
procedure ExtEdt_VendorCodeExit(Sender: TObject);
procedure FormDestroy(Sender: TObject);
procedure ExtEdt_VendorCodeButtonClick(Sender: TObject);
private
{ Private declarations }
PerSaveApInvoiceNo:String; //暂存票据号;
TaxRate_Percent:double; //当前供应商税率;
curApMonth:string; //获取已结帐月份;
Lc_CurrApInvoiceId:Integer; //当前应付发票的ID;
Lc_CurrApInvoicelogId:Integer; //当前应付发票日志的ID;
ErrRange :double; //发票匹配允许误差范围的金额
flag:integer; //操作标志位:1为新增,2为删除 ,3为暂存;
flag1:integer; //操作标志位:1为不触发AdoQry_MainInvBillFinChckChange事件,2为触发;
//fisrt:integer;
ExchRate:double;
procedure clcaAp; //计算总金额,税额,未税金额;
procedure clearedit; //清除所有具有输入焦点的控件上的内容;
procedure ReadOnly(i:integer); //为i=1使所有具有输入焦点的控件能输入资料,为i=2能输入资料;
function isequal:boolean; //判断发票货款金额与单据未税金额之和是否在误差范围之内;
procedure SaveApInvoice; //把发票的资料写入ApInvoice表中;
procedure InputInvInBillNoToApInvoice; //把匹配的入库单据号写入ApInvoiceLine表中 ;
procedure UpdateInvInBill; //修改InvInBill中财务发票匹配的资料;
procedure UpdateCurrentAp; //修改CurrentAp中相关资料;
procedure UnUpdateCurrentAp; //删除CurrentAp中相关资料;
procedure GetFieldValue(InvoiceNo:string); //返回所查询的记录;
procedure GetNoInvoiceBill; //得到未开票的入库单 ;
procedure SaveApInvoiceLog; //写入应付发票日志ApInvoiceLog;
procedure saveApInvoiceLineLog; //写入应付发票行日志ApInvoiceLineLog;
procedure UnDeleteInvInBill; //修改(删除)InvInBill中财务发票匹配的资料;
procedure DeleteApInvoice(ApInvoiceNo:string); //删除发票;
Function ApCheckout(Month:String):Boolean ; //根据月份判断该月份是否已经结账;
Function nextMonth(Month:string):string; //获取后一个月份;
procedure inputListbox; //把匹配的入库单据号写入ListBOX中;
procedure deleteListbox; //把匹配的入库单据号从ListBOX中清除;
procedure LookforInvInBill; //查找入库单明细;
function PickSlaveCode(InitCode:String):String;
function SlaveCodeUsable(R_ItemCode:String):Boolean; //
function HasPersave:String; //是否有暂存票据;
//得到暂存票据的相关资料 ;
procedure GetPerSaveInvoiceBill(PerSaveApInvoiceNo:String);
//procedure UpdatePerSaveInvInBill; //修改InvInBill中财务发票匹配(暂存)的资料;
//得到暂存票据中入库单相关资料和得到未开票的入库单;
procedure GetPerSaveAndNoApInvInBill(PerSaveApInvoiceNo:string);
procedure UpdateCurrentApp; //修改一张付款票据时,在当前应付款CurrentAp表中修改相应数据;
function isperSaveBillNo(Billno:string):boolean; //判断此发票是否为暂存票据;
procedure GetPerSaveInvInBill(PerSaveApInvoiceNo:string);//得到暂存票据中入库单相关资料 ;
procedure UnUpdateCurrentApP; //删除CurrentAp中预付款资料;
procedure UpdateApInvoiceApPayedAmount(Pay:double); //修改付款匹配金额(预付款时);
procedure UpdateApInvoiceApPayFlag(i:integer); //修改付款匹配标志(预付款时);
function IsPrePay:double; //获取预付款;
procedure MatchPay(VendorCodeS:string;CurrPay: real); //用发票匹配预付款;
procedure GetExchRate; //得到汇率;
Function IsMasterCurrency(Currency:string):boolean; //是否本位币 1:为本位币 0:为非本位币;
public
{ Public declarations }
WHCodestr,InvInBillnostr:string;
procedure InitForm(AdoConnection:TAdoConnection);
end;
var
Frm_Ap_Invoice: TFrm_Ap_Invoice;
implementation
uses Sys_Global, Ap_Invoice_Select, Base_Common, Ap_Invoice_D;
{$R *.DFM}
{ TFrm_Ap_Invoice }
procedure TFrm_Ap_Invoice.clearedit;
begin
Edt_ApInvoiceNo.text:='';
Medt_ApInvoiceDate.text:='';
Lbl_EmployeeCode.text:='';
Lbl_EmployeeName.text:='';
Medt_ApInvoiceInputDate.text:='';
ExtEdt_VendorCode.text:='';
Lbl_VendorName.text:='';
Lbl_CurrencyCode.text:='';
Lbl_CurrencyName.text:='';
Edt_ApInvoiceAmount.text:='0';
Edt_ApInvoiceTax.text:='0';
Edt_ApInvoiceRemArk.text:='';
Edt_ApInvoiceNoTax.text:='0';
AdoQry_Main.Close;
end;
procedure TFrm_Ap_Invoice.InitForm(AdoConnection: TAdoConnection);
begin
inherited;
flag1:=0;
TaxRate_Percent:=0;
SetDBConnect(AdoConnection);
AdoQry_Main.Connection:=AdoConnection;
AdoQry_ApInvoice.Connection:=AdoConnection;
AdoQry_ApInvoiceLine.Connection:=AdoConnection;
//SetSysPAra(f_LoginId,f_ModuleCode,TmpSysMenuId,f_LoginDate);
//SetUserParam('0101','','','','','');
with AdoQry_Tmp do
begin
Close;
sql.clear;
sql.Add('select ApParamValuen '+
' from ApParam '+
' where ApParamCode=''ErrRange ''');
open;
ErrRange:=fieldbyname('ApParamValuen').asfloat;
Close;
end;
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(ExtEdt_VendorCode.Text)+'''');
open;
TaxRate_Percent:=fieldbyname('VendorTaxRate_Percent').asfloat;
Close;
end;
clearedit;
PerSaveApInvoiceNo:=HasPersave;
if PerSaveApInvoiceNo<>'' then
begin
flag:=3;
Label18.Caption:='0';
Listbox1.Items.clear;
edit2.text:='';
GetPerSaveInvoiceBill(PerSaveApInvoiceNo);
if AdoQry_Main.recordCount>0 then AdoQry_Main.First ;
//GetPerSaveAndNoApInvInBill(PerSaveApInvoiceNo);
pnl_Hint.Caption:='提示:你必须先处理暂存单据!';
end;
end;
procedure TFrm_Ap_Invoice.TlBtn_NewClick(Sender: TObject);
begin
if activecontrol.Name='Edit2' then
abort;
if flag<>0 then
abort;
inherited;
flag:=1;
flag1:=0 ;
//fisrt:=0;
clearEdit;
ReadOnly(1);
TlBtn_New.enabled:=False;
TLBtn_Save.enabled:=True;
TLBtn_PerSave.enabled:=True;
TlBtn_Delete.enabled:=False;
TlBtn_Qury.Enabled:=False;
TlBtn_Cancel.Enabled:=True;
Edt_ApInvoiceNo.SetFocus ;
Medt_ApInvoiceInputDate.text:=formatdatetime('yyyy.mm.dd',now);
Medt_ApInvoicedate.text:=formatdatetime('yyyy.mm.dd',now);
Lbl_EmployeeCode.text:=userCode;
with CmBx_ApInvoiceType do
begin
Items.clear;
Items.Add('发票');
Items.Add('收据');
ItemIndex :=0;
end;
with AdoQry_tmp do
begin
Close;
sql.clear;
sql.Add('select EmployeeName '+
' from Employee '+
' where EmployeeCode='''+Trim(Lbl_EmployeeCode.text)+'''');
open;
Lbl_EmployeeName.text:=fieldbyname('EmployeeName').asstring;
Close;
end;
//Lbl_CurrencyCode.enabled:=False;
Label18.Caption:='0';
Listbox1.Items.clear;
edit2.text:='';
end;
procedure TFrm_Ap_Invoice.Edt_ApInvoiceNoExit(Sender: TObject);
begin
inherited;
if (activecontrol.Name ='TlBtn_Cancel') or (activecontrol.Name ='TlBtn_Exit') then
abort;
if flag=1 then
begin
IF Trim(Edt_ApInvoiceNo.text)='' then
begin
DispInfo('发票号不能为空!',3);
Edt_ApInvoiceNo.setfocus;
abort;
end
else
with AdoQry_Tmp do
begin
Close;
sql.clear;
sql.Add(' select ApInvoiceNo ' +
' from ApInvoice '+
' where ApInvoiceNo='''+Trim(Edt_ApInvoiceNo.text)+'''');
open;
if Not AdoQry_Tmp.Isempty then
begin
DispInfo('此发票号已存在!重新输入!',3);
Edt_ApInvoiceNo.SetFocus;
Abort;
end;
end;
end;
end;
procedure TFrm_Ap_Invoice.TlBtn_SaveClick(Sender: TObject);
var
//Total:Real ;// 发票中不含税金额 ;
//Sum1:Real ; //已匹配的单据金额之和;
I,j,k:integer;
Yearstr,Monthstr,newMonth:string;
Pay:double;
begin
inherited;
try
DateSeparator:='.';
Shortdateformat:='yyyy.mm.dd';
StrToDate(Medt_ApInvoiceInputDate.Text);
except
DispInfo(' 日期非法! ',1);
Medt_ApInvoiceInputDate.SetFocus;
Abort;
end;
try
DateSeparator:='.';
Shortdateformat:='yyyy.mm.dd';
StrToDate(Medt_ApInvoicedate.Text);
except
DispInfo(' 日期非法! ',1);
Medt_ApInvoicedate.SetFocus;
Abort;
end;
Edt_ApInvoiceAmount.OnExit (Edt_ApInvoiceAmount);
Edt_ApInvoiceTax.OnExit (Edt_ApInvoiceTax);
Edt_ApInvoiceNoTax.OnExit (Edt_ApInvoiceNoTax);
k:=0;
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) ;
Medt_ApInvoiceInputDate.setfocus;
abort;
end;
if curApMonth<>'' then
begin
newMonth:=copy(Trim(Medt_ApInvoiceInputDate.text),1,7);
if newMonth>nextMonth(nextMonth(curApMonth)) then
begin
DispInfo('不能跨月录入发票',3);
exit;
end;
end;
//对所有的控件进行检查
for i:=0 to ControlCount-1 do
begin//按OK按钮时进行全部检查
if(not Controls[i].Enabled)then
continue;
if Controls[i] is TEdit then
begin
if Assigned(TEdit(Controls[i]).OnExit) then
TEdit(Controls[i]).OnExit(Controls[i]);
end
else if Controls[i] is TMaskEdit then
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -