📄 ar_enter_gathering_d.pas
字号:
unit Ar_Enter_Gathering_D;
Interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
Base_Detail, Db, AdODB, ExtCtrls, StdCtrls, ExtEdit, Mask, linkedit;
Type
TFrm_Ar_Enter_Gathering_D = Class(TFrm_Base_Detail)
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;
Label14: TLabel;
Label15: TLabel;
medt_Createdate: TMaskEdit;
Label16: TLabel;
edt_remArk: TEdit;
edt_BtName: TEdit;
edt_CustomerName: TEdit;
edt_CurrencyName: TEdit;
edt_DeptName: TEdit;
edt_SaleEmployeeName: TEdit;
edt_CreateEmployeeName: TEdit;
edt_CustomerCode: TLinkEdit;
edt_CurrencyCode: TLinkEdit;
edt_BtCode: TLinkEdit;
edt_DeptCode: TLinkEdit;
edt_SaleEmployeeCode: TLinkEdit;
edt_CreateEmployeeCode: TLinkEdit;
procedure edt_BtCodeKeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
procedure edt_SaleEmployeeCodeExit(Sender: TObject);
procedure edt_CreateEmployeeCodeExit(Sender: TObject);
procedure edt_DeptCodeExit(Sender: TObject);
procedure edt_CustomerCodeExit(Sender: TObject);
procedure edt_BtCodeExit(Sender: TObject);
procedure edt_CurrencyCodeExit(Sender: TObject);
procedure edt_BtCodeButtonClick(Sender: TObject);
procedure edt_BtCodeChange(Sender: TObject);
procedure btn_okClick(Sender: TObject);
private
{ Private declarations }
public
TmpAmount:String;
procedure InitControls; Override;
procedure SaveData;Override;
procedure SetStatus(CurrentStatus:String;var EnableControls:String); Override;
function getCancelmode(customerCode:string):integer;
function getreMainAmount(Gatheringno:string):double;
procedure CancelGathering(Gatheringno:string);
function existsArgatherline(Gatheringno,Billno:string):boolean;
{ Public declarations }
end;
var
Frm_Ar_Enter_Gathering_D: TFrm_Ar_Enter_Gathering_D;
implementation
uses Sys_Global;
{$R *.DFM}
{ TFrm_Ar_Enter_Gathering_D }
function TFrm_Ar_Enter_Gathering_D.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;
procedure TFrm_Ar_Enter_Gathering_D.CancelGathering(Gatheringno:string);
var AdoQry:TAdoQuery;
sqltext:string;
TotalreMainAmount:double; {收款单据总余额}
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;
function TFrm_Ar_Enter_Gathering_D.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;
function TFrm_Ar_Enter_Gathering_D.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;
procedure TFrm_Ar_Enter_Gathering_D.InitControls;
var i:integer;
begin
if (Add) then
begin
SetFocus_Control:=edt_gatherno;
medt_gatherdate.Text:=formatdatetime('yyyy.mm.dd',strtodatetime(GetServerDateTime(dbconnect)));
medt_Createdate.Text:=medt_gatherdate.Text;
edt_CustomerCode.Enabled:=True;
edt_gatherno.Enabled:=True;
edt_CreateEmployeeCode.Text:=userCode;
with AdoQry_Tmp do
begin
Close;
SQL.clear;
SQL.Add('Select EmployeeCode,EmployeeName From Employee Where EmployeeCode='''+userCode+'''');
Open;
edt_CreateEmployeeName.Text:=fieldbyname('EmployeeName').asstring;
end;
end
else
begin
SetFocus_Control:=edt_CurrencyCode;
end;
inherited;
with AdoQry_Maintain do
begin
edt_gatherno.Text:=AdoQry_Maintain.fieldbyname('Gatheringno').asstring;
edt_BtCode.Text:=fieldbyname('BalanceTypeCode').asstring;
edt_BtName.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_SaleEmployeeCode.Text:=fieldbyname('SaleEmployeeCode').asstring;
edt_SaleEmployeeName.text:=fieldbyname('SalEmployeeName').asstring;
if status<>'Add' then
begin
edt_CreateEmployeeCode.Text:=fieldbyname('createEmployeeCode').asstring;
edt_CreateEmployeeName.text:=fieldbyname('createrName').asstring;
medt_Createdate.Text:=AdoQry_Maintain.fieldbyname('createdate').asstring;
medt_gatherdate.Text:=AdoQry_Maintain.fieldbyname('Gatheringdate').asstring;
end;
edt_actCode.Text:=AdoQry_Maintain.fieldbyname('actSubjectCode').asstring;
edt_rate.Text:=floattostr(AdoQry_Maintain.fieldbyname('ExchangeRate').asfloat);
edt_Billno.Text:=AdoQry_Maintain.fieldbyname('Billno').asstring;
edt_Bank.Text:=AdoQry_Maintain.fieldbyname('customerbank').asstring;
edt_Bankaccno.Text:=AdoQry_Maintain.fieldbyname('customerbank').asstring;
edt_Amount.Text:=floattostr(AdoQry_Maintain.fieldbyname('TotaltaxAmount').asfloat);
edt_remArk.Text:=AdoQry_Maintain.fieldbyname('remArk').asstring;
if not Add then
begin
edt_gatherno.Enabled:=False;
TmpAmount:=Edt_Amount.Text;
medt_Createdate.Enabled:=False;
medt_gatherdate.Enabled:=False;
edt_CustomerCode.Enabled:=False;
end;
medt_Createdate.Enabled:=False;
edt_CreateEmployeeCode.Enabled:=False;
end;
end;
procedure TFrm_Ar_Enter_Gathering_D.SaveData;
var sqltext:string;
AdoQry:TAdoQuery;
ExchRate : Double;
begin
inherited;
AdoQry:=TAdoQuery.Create(nil);
AdoQry.Connection:=dbconnect;
if (Add) and (CheckAllTypeOrderNoSet(DbConnect,10)) then
Edt_gatherno.Text := GetAllTypeOrderNo(DbConnect,10); {自动获得单据号}
try
dbconnect.beginTrans;
if Add then
if getCancelmode(Trim(edt_CustomerCode.text))=1 then
{判断该客户的销售发票核销方式是否为余额承前法,是则核销相应收款票据}
begin
sqltext:='select * from Ar_Gathering'
+' where customerCode='+quotedstr(Trim(edt_CustomerCode.text))
+' and TotaltaxAmount>isnull(TotalCancelAmount,0) ';
Executesql(AdoQry,sqltext,0);
while not AdoQry.Eof do
begin
{核销收款票据}
CancelGathering(AdoQry.fieldbyname('Gatheringno').asstring);
AdoQry.Next;
end;
end;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -