📄 apinvoiceform.pas
字号:
UpdateAction := uaAbort;
end else begin
Application.MessageBox(PChar(IntToStr(Errors[ErrorCount - 1].ErrorCode) + ': ' + E.Message + '.'), PChar(Application.Title), mb_OK + mb_DefButton1 + mb_IconStop);
UpdateAction := uaSkip;
end;
end;
end;
procedure TfrmAPInvoice.tblAPInvDetGLAccountValidate(Sender: TField);
var
LookupResults: Variant;
begin
if DBGrid1.SelectedIndex = 1 then begin
if DBGrid1.SelectedField.value = '' then exit;
LookupResults := dmLookUps.tblGLAccnt.Lookup('GLAccount', DBGrid1.SelectedField.value, 'Suspended');
if LookupResults = null then raise(exception.create('GL Account ' + '''' + DBGrid1.SelectedField.value + '''' + ' not found...' +#13 + 'Press Esc or enter a different account no'))
else if LookupResults = true then raise(exception.create('GL Account ' + '''' + DBGrid1.SelectedField.value + '''' + ' has been suspended'));
end else begin
if dmLookUps.tblGLAccntSuspended.value = true then raise(exception.create('GL Account ' + '''' + dmLookUps.tblGLAccntGLAccount.value + ': ' + dmLookUps.tblGLAccntAccountName.value + '''' + ' has been suspended'));
end
end;
procedure TfrmAPInvoice.editVendorNoExit(Sender: TObject);
begin
if editVendorNo.text <> tblAPInvVendorNo.value then begin
if editVendorNo.text <> '' then begin
if dmLookUps.tblVendor.Locate('VendorNo', editVendorNo.Text, []) <> true then begin
editVendorNo.setfocus;
raise(Exception.Create('Vendor no. ' + '''' + editVendorNo.Text + '''' + ' not found'));
end else if dmLookUps.tblVendorSuspended.value = true then begin
editVendorNo.setfocus;
raise(exception.create('Vendor no. ' + '''' + editVendorNo.Text + '''' + ' has been suspended'));
end else begin
if tblAPInv.state <> dsInsert then tblAPInv.edit;
tblAPInvVendorID.value := dmLookUps.tblVendorVendorID.value;
end;
end else begin
if tblAPInv.state <> dsInsert then tblAPInv.edit;
tblAPInvVendorID.AsVariant := null;
end;
end;
end;
procedure TfrmAPInvoice.editVendorNoKeyPress(Sender: TObject;
var Key: Char);
begin
if key = #27 then begin //Esc.
key := #0;
editVendorNo.text := tblAPInvVendorNo.value;
end;
end;
procedure TfrmAPInvoice.tblAPInvBeforeInsert(DataSet: TDataSet);
begin
TotalGLAmount := 0;
NextDetailLineNo := 1;
end;
procedure TfrmAPInvoice.tblAPInvBeforeEdit(DataSet: TDataSet);
begin
if tblAPInvPosted.value = true then raise(EAbort.create('')); //Silent Exception: "abort;" replaced by "raise etc" since abort conflicts with BDE (required by DbiSaveChanges). //Make tables read-only without having to reset "active".
TotalGLAmount := tblAPInvInvoiceAmount.value; //Assume Invoice Amount was in balance with total of GL Amounts.
qryLastDetailLineNo.close;
qryLastDetailLineNo.open;
with qryLastDetailLineNo.Fields[0] do
if IsNull then NextDetailLineNo := 1
else NextDetailLineNo := AsInteger + 1;
end;
procedure TfrmAPInvoice.tblAPInvDetBeforePost(DataSet: TDataSet);
begin
if tblAPInvDetSeq.AsVariant = null then begin //Assign Seq here rather than OnNewRecord so as not to upset grid "exit on blank record" feature.
tblAPInvDetSeq.value := NextDetailLineNo;
Inc(NextDetailLineNo);
end;
end;
procedure TfrmAPInvoice.tblAPInvDetBeforeEdit(DataSet: TDataSet);
begin
tblAPInv.edit; //Put lock on master table (if not already in dsInsert or dsEdit state).
OldGLAmount := tblAPInvDetGLAmount.value;
end;
procedure TfrmAPInvoice.tblAPInvDetBeforeInsert(DataSet: TDataSet);
begin
tblAPInv.edit; //Put lock on master table (if not already in dsInsert or dsEdit state) & get next detail line no (if not already got).
OldGLAmount := 0;
end;
procedure TfrmAPInvoice.tblAPInvDetBeforeDelete(DataSet: TDataSet);
begin
tblAPInv.edit; //Put lock on master table (if not already in dsInsert or dsEdit state).
if not (tblAPInvDet.state in [dsInsert, dsEdit]) then OldGLAmount := tblAPInvDetGLAmount.value;
end;
procedure TfrmAPInvoice.tblAPInvGLYearGetText(Sender: TField;
var Text: string; DisplayText: Boolean);
begin
if DisplayText = false then Text := Copy(tblAPInvGLYear.AsString,3,2) //If editing, show last 2 digits of year.
else Text := tblAPInvGLYear.AsString;
end;
procedure TfrmAPInvoice.tblAPInvGLYearSetText(Sender: TField;
const Text: string);
begin
if Text = '' then tblAPInvGLYear.AsVariant := null else begin //Convert 2 digit year to 4.
if (StrToInt(Text) < 0) or (StrToInt(Text) > 99) then raise(exception.create('Period invalid...' + #13 + 'Enter year as 2 digits'));
if StrToInt(Text) < 50 then tblAPInvGLYear.value := StrToInt(Text) + 2000
else tblAPInvGLYear.value := StrToInt(Text) + 1900;
end;
end;
procedure TfrmAPInvoice.tblAPInvBeforePost(DataSet: TDataSet);
var
GLDiff: currency;
APInvGLPeriodYYYYPP, EPeriodFromYYYYPP, EPeriodToYYYYPP, WPeriodFromYYYYPP, WPeriodToYYYYPP: integer;
begin
if tblAPInvPosted.value = false then begin
APInvGLPeriodYYYYPP := (tblAPInvGLYear.value * 100) + tblAPInvGLPeriod.value;
EPeriodFromYYYYPP := (frmBS1.tblCompanyEPeriodFromYYYY.value * 100) + frmBS1.tblCompanyEPeriodFromPP.value;
EPeriodToYYYYPP := (frmBS1.tblCompanyEPeriodToYYYY.value * 100) + frmBS1.tblCompanyEPeriodToPP.value;
WPeriodFromYYYYPP := (frmBS1.tblCompanyWPeriodFromYYYY.value * 100) + frmBS1.tblCompanyWPeriodFromPP.value;
WPeriodToYYYYPP := (frmBS1.tblCompanyWPeriodToYYYY.value * 100) + frmBS1.tblCompanyWPeriodToPP.value;
if frmBS1.tblCompanyFiscalYear.value = 0 then begin
with editGLPeriod do begin Show; SetFocus; end;
raise(exception.create('Current fiscal year is not yet defined...' + #13 + 'See "Your Company"'));
end;
if tblAPInvGLYear.value < frmBS1.tblCompanyFiscalYear.value then begin
with editGLPeriod do begin Show; SetFocus; end;
raise(exception.create('GL Period is prior to current fiscal year ' + #13 + 'as defined by "Your Company"'));
end;
if (APInvGLPeriodYYYYPP < EPeriodFromYYYYPP) or ((EPeriodToYYYYPP > 0) and (APInvGLPeriodYYYYPP > EPeriodToYYYYPP)) then begin
with editGLPeriod do begin Show; SetFocus; end;
raise(exception.create('GL Period is not within allowed range ' + #13 + 'as defined by "Your Company"'));
end;
if (APInvGLPeriodYYYYPP < WPeriodFromYYYYPP) or ((WPeriodToYYYYPP > 0) and (APInvGLPeriodYYYYPP > WPeriodToYYYYPP)) then begin
if Application.MessageBox(PChar('GL Period is not within expected range ' + #13 + 'as defined by "Your Company".'), PChar('Warning'), mb_OKCancel + mb_DefButton2 + mb_IconExclamation) <> IDOK then begin
with editGLPeriod do begin Show; SetFocus; end;
raise(EAbort.create('')); //Silent Exception: "abort;" replaced by "raise etc" since abort conflicts with BDE (required by DbiSaveChanges).
end;
end;
if tblAPInvDet.RecordCount = 0 then begin
with DBGrid1 do begin Show; SetFocus; end;
raise(exception.create('GL Amounts have not been entered'));
end;
GLDiff := tblAPInvInvoiceAmount.value - TotalGLAmount;
//if TotalGLAmount <> tblAPInvInvoiceAmount.value then begin //Sometimes this doesn't work. eg. if both 1 cent.
if GLDiff <> 0 then begin
with DBGrid1 do begin Show; SetFocus; end;
raise(exception.create('GL total is ' + FloatToStrF(TotalGLAmount,ffCurrency,18,2) + #13 + FloatToStrF(GLDiff,ffCurrency,18,2) + ' has yet to be allocated'));
end;
dmLookUps.tblVendor.Active := true;
if dmLookUps.tblVendor.Locate('VendorID', tblAPInvVendorID.value, []) <> true then begin
with editVendorNo do begin Show; SetFocus; end;
raise(exception.create('Vendor no longer exists')); //Deleted by another user since this user selected.
end;
end;
end;
procedure TfrmAPInvoice.tblAPInvDetAfterPost(DataSet: TDataSet);
begin
TotalGLAmount := TotalGLAmount - OldGLAmount + tblAPInvDetGLAmount.value;
end;
procedure TfrmAPInvoice.tblAPInvDetAfterDelete(DataSet: TDataSet);
begin
TotalGLAmount := TotalGLAmount - OldGLAmount;
end;
procedure TfrmAPInvoice.btnInvoiceDateClick(Sender: TObject);
begin
frmCalendar.caption := 'Invoice Date';
if tblAPInvInvoiceDate.AsVariant <> null then frmCalendar.date := tblAPInvInvoiceDate.value
else frmCalendar.date := Date;
if frmCalendar.ShowModal = mrOk then begin
tblAPInv.Edit;
tblAPInvInvoiceDate.value := frmCalendar.Date;
end;
editInvoiceDate.setfocus;
editInvoiceDate.SelectAll;
end;
procedure TfrmAPInvoice.btnDueDateClick(Sender: TObject);
begin
frmCalendar.caption := 'Due Date';
if tblAPInvDueDate.AsVariant <> null then frmCalendar.date := tblAPInvDueDate.value
else frmCalendar.date := Date;
if frmCalendar.ShowModal = mrOk then begin
tblAPInv.Edit;
tblAPInvDueDate.value := frmCalendar.Date;
end;
editDueDate.setfocus;
editDueDate.SelectAll;
end;
procedure TfrmAPInvoice.btnDiscountDateClick(Sender: TObject);
begin
frmCalendar.caption := 'Discount Date';
if tblAPInvDiscountDate.AsVariant <> null then frmCalendar.date := tblAPInvDiscountDate.value
else frmCalendar.date := Date;
if frmCalendar.ShowModal = mrOk then begin
tblAPInv.Edit;
tblAPInvDiscountDate.value := frmCalendar.Date;
end;
try
editDiscountDate.setfocus;
editDiscountDate.SelectAll;
except; end;
end;
procedure TfrmAPInvoice.DBGrid1EditButtonClick(Sender: TObject);
var
aComponent: TComponent;
begin
if DBGrid1.SelectedField = tblAPInvDetGLAccount then begin
screen.cursor := crHourglass;
aComponent := Application.FindComponent('frmGLAccountSearch');
if not Assigned (aComponent) then frmGLAccountSearch := TfrmGLAccountSearch.Create(Application);
frmGLAccountSearch.GLAccount := tblAPInvDetGLAccount.value;
screen.cursor := crDefault;
if frmGLAccountSearch.ShowModal = mrOk then begin
tblAPInvDet.Edit;
tblAPInvDetGLAccount.value := frmGLAccountSearch.GLAccount;
end;
end;
end;
procedure TfrmAPInvoice.DBGrid1KeyPress(Sender: TObject; var Key: Char);
begin
if (Key = ^J) and (DBGrid1.SelectedField = tblAPInvDetGLAccount) then begin //Ctrl+Enter show GLAccount Search.
Key := #0;
try DBGrid1EditButtonClick(sender); except; end;
end;
end;
procedure TfrmAPInvoice.mnuNewClick(Sender: TObject);
begin
tblAPInvDet.append;
DBGrid1.SelectedIndex := 0;
end;
procedure TfrmAPInvoice.mnuDeleteClick(Sender: TObject);
begin
try tblAPInvDet.delete; except; end;
end;
procedure TfrmAPInvoice.tblAPInvVendorIDValidate(Sender: TField);
begin
if dmLookUps.tblVendor.Lookup('VendorID', tblAPInvVendorID.value, 'Suspended') = true then raise(exception.create('Vendor ' + '''' + dmLookUps.tblVendorVendorNo.value + ': ' + dmLookUps.tblVendorVendorName.value + '''' + ' has been suspended')); //Catch suspended vendor selected from combobox.
end;
procedure TfrmAPInvoice.DBGrid1ColEnter(Sender: TObject);
begin
if (DBGrid1.Focused = true) //Prevent problem when Shift Tab out of grid, ColEnter (on last column) fires after GridExit.
and (DBGrid1.SelectedIndex >0) then DBGrid1.Options := [dgEditing,dgAlwaysShowEditor,dgTitles,dgIndicator,dgColumnResize,dgColLines,dgRowLines,dgTabs,dgConfirmDelete,dgCancelOnExit]; //Toggle dgAlwaysShowEditor to prevent 1st field from being left-justified if always dgAlwaysShowEditor.
end;
procedure TfrmAPInvoice.tblAPInvInvoiceDateSetText(Sender: TField;
const Text: string);
begin
{var
Year, Month, Day: Word;
begin
//if Text = '' then tblAPInvInvoiceDate.AsVariant := null //Not required (editmask prevents).
if Text = '02/29/00' then tblAPInvInvoiceDate.value := StrToDate('02/29/2000')
else begin
DecodeDate(StrToDate(text), Year, Month, Day);
if (Year < 1950) and (Year > 1899) then begin
Year := Year + 100;
tblAPInvInvoiceDate.value := StrToDate(IntToStr(Month) + '/' + IntToStr(Day) + '/' + IntToStr(Year));
end else tblAPInvInvoiceDate.value := StrToDate(Text);
end;}
tblAPInvInvoiceDate.value := frmBS1.Date2000(Text);
end;
procedure TfrmAPInvoice.tblAPInvDueDateSetText(Sender: TField;
const Text: string);
begin
tblAPInvDueDate.value := frmBS1.Date2000(Text);
end;
procedure TfrmAPInvoice.tblAPInvDiscountDateSetText(Sender: TField;
const Text: string);
begin
tblAPInvDiscountDate.value := frmBS1.Date2000(Text);
end;
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -