📄 apchequeform.pas
字号:
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 tblAPCheqGLPeriod.AsVariant = null then begin
with editGLPeriod do begin Show; SetFocus; end;
raise(exception.create('Field ' + '''' + 'Period' + '''' + ' must have a value'));
end;
if (JVGLPeriodYYYYPP < EPeriodFromYYYYPP) or ((EPeriodToYYYYPP > 0) and (JVGLPeriodYYYYPP > 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 (JVGLPeriodYYYYPP < WPeriodFromYYYYPP) or ((WPeriodToYYYYPP > 0) and (JVGLPeriodYYYYPP > 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 tblAPInvChq.RecordCount = 0 then begin
with DBGrid1 do begin Show; SetFocus; end;
raise(exception.create('Invoices have not been entered'));
end;
if tblAPCheqChequeAmount.value < 0 then begin
with DBGrid1 do begin Show; SetFocus; end;
raise(exception.create('Cheque Amount cannot be less than zero'));
end;
end;
end;
end;
procedure TfrmAPCheque.tblAPInvChqAfterPost(DataSet: TDataSet);
begin
tblAPCheqChequeAmount.AsCurrency := tblAPCheqChequeAmount.value - OldPaymentAmount + tblAPInvChqPaymentAmount.value; //Remove old & add new.
if (Seqs.IndexOf(IntToStr(tblAPInvChqSeq.value)) > -1) then APInvoiceIDs[Seqs.IndexOf(IntToStr(tblAPInvChqSeq.value))] := tblAPInvChqAPInvoiceID.AsString
else begin
APInvoiceIDs.Add(tblAPInvChqAPInvoiceID.AsString);
Seqs.Add(tblAPInvChqSeq.AsString);
end;
end;
procedure TfrmAPCheque.tblAPInvChqAfterDelete(DataSet: TDataSet);
begin
tblAPCheqChequeAmount.AsCurrency := tblAPCheqChequeAmount.value - OldPaymentAmount; //Remove old.
if tblAPInvChq.RecordCount = 0 then tblAPCheqChequeAmount.AsVariant := null;
if (Seqs.IndexOf(IntToStr(OldSeq)) > -1) then begin
APInvoiceIDs.Delete(Seqs.IndexOf(IntToStr(OldSeq)));
Seqs.Delete(Seqs.IndexOf(IntToStr(OldSeq)));
end;
end;
procedure TfrmAPCheque.btnChequeDateClick(Sender: TObject);
begin
frmCalendar.caption := 'Cheque Date';
if tblAPCheqChequeDate.AsVariant <> null then frmCalendar.date := tblAPCheqChequeDate.value
else frmCalendar.date := Date;
if frmCalendar.ShowModal = mrOk then begin
tblAPCheq.Edit;
tblAPCheqChequeDate.value := frmCalendar.Date;
end;
editChequeDate.setfocus;
editChequeDate.SelectAll;
end;
procedure TfrmAPCheque.mnuDeleteClick(Sender: TObject);
begin
try tblAPInvChq.delete; except; end;
end;
procedure TfrmAPCheque.mnuNewClick(Sender: TObject);
begin
tblAPInvChq.append;
DBGrid1.SelectedIndex := 0;
end;
procedure TfrmAPCheque.tblAPCheqBeforeInsert(DataSet: TDataSet);
begin
NextDetailLineNo := 1;
end;
procedure TfrmAPCheque.tblAPInvChqBeforePost(DataSet: TDataSet);
begin
if tblAPInvChqSeq.AsVariant = null then begin //Assign Seq here rather than OnNewRecord so as not to upset grid "exit on blank record" feature.
tblAPInvChqSeq.value := NextDetailLineNo;
Inc(NextDetailLineNo);
end;
end;
procedure TfrmAPCheque.tblAPInvChqAPInvoiceIDValidate(Sender: TField);
begin
if tblAPInvPosted.value <> true then raise(exception.create('Invoice ' + '''' + tblAPInvInvoiceNo.value + '''' + ' has not been posted'));
if (APInvoiceIDs.IndexOf(IntToStr(tblAPInvChqAPInvoiceID.value)) > -1) then //Error if invoice is already on cheque and it's not this invoice.
if (tblAPInvChqSeq.AsString <> Seqs[APInvoiceIDs.IndexOf(IntToStr(tblAPInvChqAPInvoiceID.value))]) then
raise(exception.create('Invoice ' + '''' + tblAPInvInvoiceNo.value + '''' + ' is already on this cheque'));
end;
procedure TfrmAPCheque.tblAPInvChqAPInvoiceIDChange(Sender: TField);
begin
if (tblAPInvChqOwing.value <> 0) and (tblAPInvChqDiscountTaken.value <> true) and (tblAPCheqChequeDate.value <= tblAPInvChqDiscountDate.value) then tblAPInvChqPaymentAmount.AsCurrency := tblAPInvChqOwing.value - tblAPInvChqDiscountAmount.value //Set default payment amount.
else tblAPInvChqPaymentAmount.AsCurrency := tblAPInvChqOwing.value;
end;
procedure TfrmAPCheque.tblAPInvChqPaymentAmountValidate(Sender: TField);
var
AmountDue, PaymentAmount: Currency;
begin
if (tblAPInvChqOwing.value <> 0) and (tblAPCheqChequeDate.value <= tblAPInvChqDiscountDate.value) then AmountDue := tblAPInvChqOwing.value - tblAPInvChqDiscountAmount.value
else AmountDue := tblAPInvChqOwing.value;
//if AmountDue < 0 then begin
//if tblAPInvChqPaymentAmount.value < AmountDue then raise(exception.create('Payment exceeds amount due'));
//end else if tblAPInvChqPaymentAmount.value > AmountDue then raise(exception.create('Payment exceeds amount due'));
PaymentAmount := tblAPInvChqPaymentAmount.value; //Prevent Delphi bug where it says payment exceeds amount due yet they are the same (eg. $10 invoice, .20 disc, 9.80 due, payment 9.80)... gave error in office, but not kitchen.
if AmountDue < 0 then begin
if PaymentAmount < AmountDue then raise(exception.create('Payment exceeds amount due'));
end else if PaymentAmount > AmountDue then raise(exception.create('Payment exceeds amount due'));
end;
procedure TfrmAPCheque.tblAPCheqChequeNoValidate(Sender: TField);
//var
//LookupResults: variant;
begin
//tblAPCheq2.Active := true; //Suppressed to improve efficiency.
//LookupResults := tblAPCheq2.Lookup('ChequeNo', tblAPCheqChequeNo.value, 'ChequeID');
//if (LookupResults <> null) and (LookupResults <> tblAPCheqChequeID.value) then begin
//if Application.MessageBox(PChar('Cheque no. ' + '''' + tblAPCheqChequeNo.AsString + '''' + ' already exists.'), PChar('Warning'), mb_OKCancel + mb_DefButton2 + mb_IconExclamation) <> IDOK then begin
//with editChequeNo do begin Show; SetFocus; end;
//abort;
//end;
//end;
end;
procedure TfrmAPCheque.editVendorNoExit(Sender: TObject);
begin
if editVendorNo.text <> tblAPCheqVendorNo.value then begin
if tblAPInvChq.RecordCount >0 then begin
editVendorNo.setfocus;
raise(exception.create('Vendor cannot be changed unless invoices are removed first'));
end;
if editVendorNo.text <> '' then begin
if tblVendor.Locate('VendorNo', editVendorNo.Text, []) <> true then begin
editVendorNo.setfocus;
raise(Exception.Create('Vendor no. ' + '''' + editVendorNo.Text + '''' + ' not found'));
//end else if tblVendorSuspended.value = true then begin
//editVendorNo.setfocus;
//raise(exception.create('Vendor no. ' + '''' + editVendorNo.Text + '''' + ' has been suspended'));
end else begin
if tblAPCheq.state <> dsInsert then tblAPCheq.edit;
tblAPCheqVendorID.value := tblVendorVendorID.value;
end;
end else begin
if tblAPCheq.state <> dsInsert then tblAPCheq.edit;
tblAPCheqVendorID.AsVariant := null;
end;
end;
end;
procedure TfrmAPCheque.editVendorNoKeyPress(Sender: TObject;
var Key: Char);
begin
if key = #27 then begin //Esc.
key := #0;
editVendorNo.text := tblAPCheqVendorNo.value;
end;
end;
procedure TfrmAPCheque.cboVendorKeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
begin
if key = VK_Delete then begin
tblAPCheq.Edit;
tblAPCheqVendorID.AsVariant := null;
end;
end;
procedure TfrmAPCheque.btnVendorClick(Sender: TObject);
var
aComponent: TComponent;
begin
screen.cursor := crHourglass;
aComponent := Application.FindComponent('frmVendors');
if Assigned (aComponent) then try frmVendors.qryVendor.close; frmVendors.qryVendor.open; except; end
else frmVendors := TfrmVendors.Create(Application);
aComponent := Application.FindComponent('frmVendorsFilter');
if Assigned (aComponent) then try frmVendorsFilter.btnResetClick(sender); except; end;
frmVendors.mnuFilter.Checked := false;
frmVendors.qryVendor.Filtered := false;
frmVendors.tblVendor.Filtered := false;
if frmVendors.WindowState = wsMinimized then frmVendors.WindowState := wsNormal;
if frmVendors.visible = true then frmVendors.FormShow(sender)
else frmVendors.Show;
if not frmVendors.qryVendor.Locate('VendorID', tblAPCheqVendorID.value, []) then frmVendors.qryVendor.First;
screen.cursor := crDefault;
end;
procedure TfrmAPCheque.cboBankKeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
begin
if key = VK_Delete then begin
tblAPCheq.Edit;
tblAPCheqBankID.AsVariant := null;
end;
end;
procedure TfrmAPCheque.btnBankClick(Sender: TObject);
var
aComponent: TComponent;
begin
screen.cursor := crHourglass;
aComponent := Application.FindComponent('frmBanks');
if not Assigned (aComponent) then frmBanks := TfrmBanks.Create(Application);
if frmBanks.WindowState = wsMinimized then frmBanks.WindowState := wsNormal;
if frmBanks.visible = true then frmBanks.FormShow(sender)
else frmBanks.Show;
if not frmBanks.tblBank.Locate('BankID', tblAPCheqBankID.value, []) then frmBanks.tblBank.First;
screen.cursor := crDefault;
end;
procedure TfrmAPCheque.tblAPInvFilterRecord(DataSet: TDataSet;
var Accept: Boolean);
var
Owing: currency;
begin
Accept := true;
if tblAPInvVendorID.value <> tblAPCheqVendorID.value then Accept := false
else begin
Owing := tblAPInvOwing.value; //Prevent Delphi bug where 0 owing invoices show (0 stored as -7.21E-16).
if (tblAPInvChqAPInvoiceID.AsVariant = null) and (Owing = 0) then Accept := false //New invoice: don't show zero balance invoices (in combobox).
else if (tblAPInvChqAPInvoiceID.value <> tblAPInvAPInvoiceID.value) and (Owing = 0) then Accept := false; //Unless this invoice exists from before, don't show zero balance invoices (in combobox).
end;
end;
procedure TfrmAPCheque.tblAPCheqVendorIDValidate(Sender: TField);
begin
if tblAPInvChq.RecordCount >0 then raise(exception.create('Vendor cannot be changed unless invoices are removed first'));
end;
procedure TfrmAPCheque.tblAPCheqVendorIDChange(Sender: TField);
begin
if tblAPCheqVendorID.AsVariant <> null then begin //Set bank if not yet entered or currency doesn't match.
if (tblAPCheqBankID.AsVariant = null) or (tblAPCheqCurrencyIDofBank.value <> tblAPCheqCurrencyIDofVendor.value) then begin
dmLookUps.tblBank.first;
while not dmLookUps.tblBank.eof do begin
if dmLookUps.tblBankCurrencyID.value = tblAPCheqCurrencyIDofVendor.value then begin
tblAPCheq.Edit;
tblAPCheqBankID.value := dmLookUps.tblBankBankID.value;
end;
dmLookUps.tblBank.next;
end;
end;
end;
end;
procedure TfrmAPCheque.dsAPCheqUpdateData(Sender: TObject);
begin
if tblAPCheqBankID.AsVariant = null then begin //Validate here rather than BeforePost otherwise setfocus won't work (BankID is a mandatory field).
with cboBank do begin Show; SetFocus; end;
raise(exception.create('Field ' + '''Bank''' + ' must have a value'));
end;
end;
procedure TfrmAPCheque.chkVoidClick(Sender: TObject);
begin
if Screen.ActiveControl.name = 'chkVoid' then begin //Prevent firing when form displays.
if chkVoid.checked = true then begin
tblAPCheq.Edit;
tblAPCheqChequeDate.AsVariant := null;
tblAPCheqGLPeriod.AsVariant := null;
tblAPCheqGLYear.AsVariant := null;
end else begin
tblAPCheq.Edit;
tblAPCheqChequeDate.value := Date;
if frmBS1.tblCompanyDefaultPeriodPP.value > 0 then tblAPCheqGLPeriod.value := frmBS1.tblCompanyDefaultPeriodPP.value;
if frmBS1.tblCompanyDefaultPeriodYYYY.value > 0 then tblAPCheqGLYear.value := frmBS1.tblCompanyDefaultPeriodYYYY.value;
end;
end;
end;
procedure TfrmAPCheque.tblAPCheqChequeDateSetText(Sender: TField;
const Text: string);
begin
if Text = ' / / ' then tblAPCheqChequeDate.AsVariant := null
else tblAPCheqChequeDate.value := frmBS1.Date2000(Text);
end;
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -