📄 ar_enter_gatheringinvoice.pas
字号:
unit Ar_Enter_GatheringInvoice;
Interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
Base_Entry_Body, ExtPrintReport, Db, ActnList, AdODB, Grids, DBGridEh,
ExtCtrls, ComCtrls, ToolWin, Mask, StdCtrls, jpeg, linkedit;
Type
TFrm_Ar_Enter_GatheringInvoice = Class(TFrm_Base_Entry_Body)
Label1: TLabel;
edt_gatherno: TEdit;
Label2: TLabel;
Label4: TLabel;
medt_gatherdate: TMaskEdit;
Label5: TLabel;
Label3: TLabel;
edt_actCode: TEdit;
Label6: TLabel;
Label7: TLabel;
edt_rate: TEdit;
Label8: TLabel;
edt_Billno: TEdit;
Label9: TLabel;
edt_Bank: TEdit;
Label10: TLabel;
edt_Bankaccno: TEdit;
Label11: TLabel;
edt_Amount: TEdit;
Label12: TLabel;
Label13: TLabel;
Label16: TLabel;
edt_remArk: TEdit;
Label17: TLabel;
edt_CancelAmount: TEdit;
AdoQry_BodyGatheringNo: TStringField;
AdoQry_BodyBillNo: TStringField;
AdoQry_BodySaleDeptCode: TStringField;
AdoQry_BodySaleEmployeeCode: TStringField;
AdoQry_BodyBillDate: TDateTimeField;
AdoQry_BodyTotalAmount: TFloatField;
AdoQry_BodyThiSCancelAmount: TFloatField;
edt_CustomerName: TEdit;
edt_BalanceTypeName: TEdit;
edt_CurrencyName: TEdit;
edt_DeptName: TEdit;
edt_EmployeeName: TEdit;
AdoQry_BodyReMainTotalAmount: TFloatField;
AdoQry_BodyDeptflag: TStringField;
AdoQry_BodySaleEmployeeflag: TStringField;
AdoQry_BodyID: TAutoIncField;
AdoQry_BodyDeptName: TStringField;
AdoQry_BodyEmployeeName: TStringField;
edt_CustomerCode: TLinkEdit;
edt_BalanceTypeCode: TLinkEdit;
edt_DeptCode: TLinkEdit;
edt_EmployeeCode: TLinkEdit;
edt_CurrencyCode: TLinkEdit;
Label14: TLabel;
Medt_InAccountDate: TMaskEdit;
procedure FormCreate(Sender: TObject);
procedure FormClose(Sender: TObject; var Action: TCloseAction);
procedure Act_SaveExecute(Sender: TObject);
procedure Act_autoExecute(Sender: TObject);
procedure FormShow(Sender: TObject);
procedure edt_CustomerCodeExit(Sender: TObject);
procedure edt_CurrencyCodeExit(Sender: TObject);
procedure edt_BalanceTypeCodeKeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
procedure edt_BalanceTypeCodeButtonClick(Sender: TObject);
procedure edt_BalanceTypeCodeExit(Sender: TObject);
procedure edt_DeptCodeExit(Sender: TObject);
procedure edt_EmployeeCodeExit(Sender: TObject);
procedure FormActivate(Sender: TObject);
procedure Medt_InAccountDateExit(Sender: TObject);
private
{ Private declarations }
public
realstatus:string;
TmpAmount :String;
procedure InitForm(AdOConnection:TAdOConnection;FormStatus:String;
AdoQuery:TAdoQuery);Override;
procedure SetStatus(CurrentStatus:String;var AnswerStatus,EnableControls:String); Override;
procedure InitControls; Override;
procedure SaveData; Override;
function existsgatherline(gatherno:string;Billno:string):boolean;
procedure CancelGathering(Gatheringno:string);
function getreMainAmount(Gatheringno:string):double;
function existsArgatherline(Gatheringno,Billno:string):boolean;
function getCancelmode(customerCode:string):integer;
{ Public declarations }
end;
var
Frm_Ar_Enter_GatheringInvoice: TFrm_Ar_Enter_GatheringInvoice;
TotalCancelAmount:Double;
implementation
uses Sys_Global,Ar_Enter_GatheringInvoice_D;
{$R *.DFM}
function TFrm_Ar_Enter_GatheringInvoice.getCancelmode(customerCode:string):integer;
var AdoQry:TAdoQuery;
sqltext:string;
begin
Result:=-1;
AdoQry:=TAdoQuery.Create(nil);
AdoQry.Connection:=dbconnect;
try
sqltext:='select SalInvoiceCancelmode from customer '
+' where customerCode='+quotedstr(customerCode);
Executesql(AdoQry,sqltext,0) ;
if not AdoQry.Eof then
Result:=AdoQry.fieldbyname('SalInvoiceCancelmode').asinteger;
finally
AdoQry.Free;
end;
end;
function TFrm_Ar_Enter_GatheringInvoice.existsArgatherline(Gatheringno,Billno:string):boolean;
var AdoQry:TAdoQuery;
sqltext:string;
begin
Result:=False;
AdoQry:=TAdoQuery.Create(nil);
AdoQry.Connection:=dbconnect;
try
sqltext:='select Gatheringno from Ar_Gatheringline '
+' where Gatheringno='+quotedstr(Gatheringno)
+' and Billno='+quotedstr(Billno);
Executesql(AdoQry,sqltext,0) ;
if not AdoQry.Eof then Result := True;
finally
AdoQry.Free;
end;
end;
function TFrm_Ar_Enter_GatheringInvoice.getreMainAmount(Gatheringno:string):double;
var AdoQry:TAdoQuery;
sqltext:string;
begin
Result:=-1;
AdoQry:=TAdoQuery.Create(nil);
AdoQry.Connection:=dbconnect;
try
sqltext:='select TotaltaxAmount-isnull(TotalCancelAmount,0) as reMainAmount from Ar_Gathering '
+' where Gatheringno='+quotedstr(Gatheringno);
Executesql(AdoQry,sqltext,0) ;
if not AdoQry.Eof then
Result:=AdoQry.fieldbyname('reMainAmount').asfloat;
finally
AdoQry.Free;
end;
end;
procedure TFrm_Ar_Enter_GatheringInvoice.CancelGathering(Gatheringno:string);
var AdoQry:TAdoQuery;
sqltext:string;
TotalreMainAmount:double; {收款单据总余额}//TotalReMainAmount
thiSCancelAmount:double;{此次核销金额}
begin
TotalreMainAmount:=-1;
thiSCancelAmount:=0;
AdoQry:=TAdoQuery.Create(nil);
AdoQry.Connection:=dbconnect;
AdoQry.EnableBCD:=False;
try
TotalreMainAmount:=getreMainAmount(Gatheringno);{获得当前收款票据的余额}
if TotalreMainAmount<=0 then exit;
sqltext:=' select sa_SaleInvoice.Invoiceno, sa_SaleInvoice.SaleDeptCode,'
+' sa_SaleInvoice.SaleEmployeeCode, '
+' sa_SaleInvoice.Billdate, '
+' sa_SaleInvoice.TotaltaxAmount, '
+' sa_SaleInvoice.TotaltaxAmount-sa_SaleInvoice.CancelAmount as reMainAmount'
+' from sa_SaleInvoice '
+' where isnull(sa_SaleInvoice.CancelAmount,0)<TotaltaxAmount '
+' and customerCode='+quotedstr(edt_CustomerCode.text)
+' and active = 1 ';
Executesql(AdoQry,sqltext,0); {获得当前客户的未全核销的销售发票}
while (not AdoQry.Eof) and (TotalreMainAmount>0) do
begin
thiSCancelAmount:=AdoQry.fieldbyname('reMainAmount').asfloat;
if AdoQry.fieldbyname('reMainAmount').asfloat>=TotalreMainAmount then
thiSCancelAmount:=TotalreMainAmount;
{thiSCancelAmount为此次核销金额}
// sqltext:='select * from Ar_gather'
if existsArgatherline(Gatheringno,AdoQry.fieldbyname('Invoiceno').asstring) then
//判断在收款票据表体中是否存在该销售发票的记录
begin
sqltext:='update Ar_Gatheringline'
+' set thiSCancelAmount=thiSCancelAmount+'+floattostr(thiSCancelAmount)
+' where Gatheringno='+quotedstr(Gatheringno)
+' and Billno='+quotedstr(AdoQry.fieldbyname('Invoiceno').asstring);
Executesql(AdoQry_tmp,sqltext,1) ;
end
else
begin
sqltext:='insert into Ar_Gatheringline(Gatheringno,Billno,SaleDeptCode,SaleEmployeeCode,Billdate,TotalAmount,reMainTotalAmount,thiSCancelAmount)'
+' Values('+quotedstr(Gatheringno)+','
+quotedstr(AdoQry.fieldbyname('Invoiceno').asstring)+','
+quotedstr(AdoQry.fieldbyname('SaleDeptCode').asstring)+','
+quotedstr(AdoQry.fieldbyname('SaleEmployeeCode').asstring)+','
+quotedstr(AdoQry.fieldbyname('Billdate').asstring)+','
+floattostr(AdoQry.fieldbyname('TotaltaxAmount').asfloat)+','
+floattostr(AdoQry.fieldbyname('reMainAmount').asfloat)+','
+floattostr(thiSCancelAmount)+')';
Executesql(AdoQry_tmp,sqltext,1);{插入记录到收款票据表体}
end;
sqltext:=' update sa_SaleInvoice'
+' set CancelAmount=isnull(CancelAmount,0)+'+floattostr(thiSCancelAmount)
+' where Invoiceno='+quotedstr(AdoQry.fieldbyname('Invoiceno').asstring);
Executesql(AdoQry_tmp,sqltext,1); {累加销售发票的核销金额}
sqltext:=' update Ar_Gathering '
+' set TotalCancelAmount=TotalCancelAmount+'+floattostr(thiSCancelAmount)
+' where Gatheringno='+quotedstr(Gatheringno);
Executesql(AdoQry_tmp,sqltext,1);{累加收款票据的总核销金额}
TotalreMainAmount:=TotalreMainAmount-thiSCancelAmount;{扣减总余额数}
AdoQry.Next;
end;
finally
AdoQry.Free;
end;
end;
procedure TFrm_Ar_Enter_GatheringInvoice.InitForm(AdOConnection:TAdOConnection;FormStatus:String;
AdoQuery:TAdoQuery);
begin
inherited;
end;
procedure TFrm_Ar_Enter_GatheringInvoice.InitControls;
var sqltext:string;
begin
realstatus:=status;
if status='Add' then
begin
SetFocus_Control:=edt_gatherno;
edt_gatherno.Enabled := True;
end
else
begin
// status:='Add';
SetFocus_Control:=edt_BalanceTypeCode;
end;
inherited;
if realstatus<>'Add' then
begin
act_insertline.Enabled:=False;
// Act_Modify.Enabled := False;
Act_Auto.Enabled := True;
act_Deleteline.Enabled:=False;
end;
if realstatus='Query' then
begin
act_Modify.Enabled:=False;
act_auto.Enabled:=False;
end;
act_insertline.Enabled:=False;
act_Deleteline.Enabled:=False;
with AdoQry_Head do
begin
edt_gatherno.Text := IifString(Status='Add','',AdoQry_Head.fieldbyname('Gatheringno').asstring);
edt_BalanceTypeCode.Text := fieldbyname('BalanceTypeCode').asstring;
edt_BalanceTypeName.Text := fieldbyname('BalanceTypeName').asstring;
edt_CustomerCode.Text := fieldbyname('customerCode').asstring;
edt_CustomerName.Text := fieldbyname('customerName').asstring;
edt_CurrencyCode.Text := fieldbyname('currencyCode').asstring;
edt_CurrencyName.text := fieldbyname('currencyName').asstring;
edt_DeptCode.Text:=fieldbyname('SaleDeptCode').asstring;
edt_DeptName.text:=fieldbyname('DeptName').asstring;
edt_EmployeeCode.Text:=fieldbyname('SaleEmployeeCode').asstring;
edt_EmployeeName.Text:=fieldbyname('EmployeeName').asstring;
medt_gatherdate.Text:=IIFString(Status='Add' ,FormatDateTime('yyyy.mm.dd',Date),AdoQry_Head.fieldbyname('Gatheringdate').asstring);
medt_InAccountdate.Text:=IIFString(Status='Add' ,FormatDateTime('yyyy.mm.dd',Date),AdoQry_Head.fieldbyname('InAccountDate').asstring);
edt_actCode.Text:=AdoQry_Head.fieldbyname('actSubjectCode').asstring;
edt_rate.Text:=floattostr(AdoQry_Head.fieldbyname('ExchangeRate').asfloat);
edt_Billno.Text:=AdoQry_Head.fieldbyname('Billno').asstring;
edt_Bank.Text:=AdoQry_Head.fieldbyname('customerbank').asstring;
edt_Bankaccno.Text:=AdoQry_Head.fieldbyname('customerbank').asstring;
edt_Amount.Text:=floattostr(AdoQry_Head.fieldbyname('TotaltaxAmount').asfloat);
edt_CancelAmount.Text:=floattostr(AdoQry_Head.fieldbyname('TotalCancelAmount').asfloat) ;
If Status='Add' then Edt_CancelAmount.Text := '0';
Edt_CancelAmount.Enabled := False;
edt_remArk.Text:=AdoQry_Head.fieldbyname('remArk').asstring;
if not (status='Add') then
begin
edt_gatherno.Enabled:=False;
TmpAmount := Edt_Amount.Text;
end;
{ if 1=1 then //status='Add' then
begin
sqltext:='select top 0 Ar_Gatheringline.*, '
+' DeptName, '
+' SaleDeptCode+'' ''+DeptName as Deptflag, '
+' EmployeeName, '
+' SaleEmployeeCode+'' ''+EmployeeName as SaleEmployeeflag '
+' from Ar_Gatheringline '
+' left join Dept on Ar_Gatheringline.SaleDeptCode=Dept.DeptCode '
+' left join Employee on Ar_Gatheringline.SaleEmployeeCode=Employee.EmployeeCode '
+' where Gatheringno='+quotedstr(edt_gatherno.text);
Executesql(AdoQry_Body,sqltext,0);
end
else }
begin
{ sqltext:=' select Ar_Gatheringline.id, '
+' Ar_Gatheringline.Gatheringno, '
+' Ar_Gatheringline.Billno, '
+' Ar_Gatheringline.SaleDeptCode, '
+' Ar_Gatheringline.SaleEmployeeCode, '
+' Ar_Gatheringline.Billdate, '
+' Ar_Gatheringline.TotalAmount, '
+' Ar_Gatheringline.thiSCancelAmount, '
// +' Ar_Gatheringline.reMainTotalAmount, '
+' sa_SaleInvoice.TotaltaxAmount-isnull(sa_SaleInvoice.CancelAmount,0) as reMainTotalAmount, '
+' Dept.DeptName, '
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -