📄 arinvoicesform.pas
字号:
tblARInv.Active := true;
tblARInv.Database.TransIsolation := tiDirtyRead;
if tblARInv.Locate('ARInvoiceID', qryARInvARInvoiceID.value, []) = true then begin
tblARInv.delete; //Delete from table as query is read-only.
tblARInv.Database.ApplyUpdates([tblARInvDet, tblARInv]);
DbiSaveChanges(tblARInvDet.handle);
DbiSaveChanges(tblARInv.handle);
Bookmark := qryARInv.GetBookmark;
with qryARInv do begin close; open; end; //Refresh.
try qryARInv.GotoBookmark(Bookmark); except; end;
qryARInv.FreeBookmark(BookMark);
if qryARInvARInvoiceID.AsVariant = null then qryARInv.first; //If deleting last record, prevent blank record with focus after last record (move to 1st record as per other grids).
end;
end;
procedure TfrmARInvoices.mnuExitClick(Sender: TObject);
begin
Close;
end;
procedure TfrmARInvoices.qryARInvCalcFields(DataSet: TDataSet);
begin
qryARInvPeriodppyyyy.value := qryARInvGLPeriod.AsString + '/' + qryARInvGLYear.AsString;
qryARInvAge.value := Round(Date() - qryARInvInvoiceDate.value);
end;
procedure TfrmARInvoices.mnuSortDateAscendingClick(Sender: TObject);
begin
screen.cursor := crHourglass;
mnuSortDate.checked := true;
mnuSortDateAscending.checked := true;
qryARInv.close;
qryARInv.sql[0] := 'SELECT I.*, C.CustomerNo BillToNo, C.CustomerName BillToName, C.CurrencyID, C.Phone, C.EMail FROM ARInv I INNER JOIN Customer C ON I.BillToID = C.CustomerID';
qryARInv.sql[2] := 'ORDER BY I.InvoiceDate, I.InvoiceNo';
qryARInv.open;
screen.cursor := crDefault;
end;
procedure TfrmARInvoices.mnuSortDateDescendingClick(Sender: TObject);
begin
screen.cursor := crHourglass;
mnuSortDate.checked := true;
mnuSortDateDescending.checked := true;
qryARInv.close;
qryARInv.sql[0] := 'SELECT I.*, C.CustomerNo BillToNo, C.CustomerName BillToName, C.CurrencyID, C.Phone, C.EMail FROM ARInv I INNER JOIN Customer C ON I.BillToID = C.CustomerID';
qryARInv.sql[2] := 'ORDER BY I.InvoiceDate DESC, I.InvoiceNo DESC';
qryARInv.open;
screen.cursor := crDefault;
end;
procedure TfrmARInvoices.mnuSortNameClick(Sender: TObject);
begin
screen.cursor := crHourglass;
mnuSortName.checked := true;
mnuSortDateAscending.checked := false;
mnuSortDateDescending.checked := false;
qryARInv.close;
qryARInv.sql[0] := 'SELECT I.*, C.CustomerNo BillToNo, C.CustomerName BillToName, C.CurrencyID, C.Phone, C.EMail FROM ARInv I INNER JOIN Customer C ON I.BillToID = C.CustomerID';
qryARInv.sql[2] := 'ORDER BY C.BillToName, C.BillToNo, I.InvoiceDate, I.InvoiceNo';
qryARInv.open;
screen.cursor := crDefault;
end;
procedure TfrmARInvoices.mnuSortAmountClick(Sender: TObject);
begin
screen.cursor := crHourglass;
mnuSortAmount.checked := true;
mnuSortDateAscending.checked := false;
mnuSortDateDescending.checked := false;
qryARInv.close;
qryARInv.sql[0] := 'SELECT I.*, C.CustomerNo BillToNo, C.CustomerName BillToName, C.CurrencyID, C.Phone, C.EMail FROM ARInv I INNER JOIN Customer C ON I.BillToID = C.CustomerID';
qryARInv.sql[2] := 'ORDER BY I.InvoiceAmount DESC, I.InvoiceDate';
qryARInv.open;
screen.cursor := crDefault;
end;
procedure TfrmARInvoices.mnuSortOwingClick(Sender: TObject);
begin
screen.cursor := crHourglass;
mnuSortOwing.checked := true;
mnuSortDateAscending.checked := false;
mnuSortDateDescending.checked := false;
qryARInv.close;
qryARInv.sql[0] := 'SELECT I.*, C.CustomerNo BillToNo, C.CustomerName BillToName, C.CurrencyID, C.Phone, C.EMail FROM ARInv I INNER JOIN Customer C ON I.BillToID = C.CustomerID';
qryARInv.sql[2] := 'ORDER BY I.Owing DESC, I.InvoiceDate';
qryARInv.open;
screen.cursor := crDefault;
end;
procedure TfrmARInvoices.mnuSortBillToNoClick(Sender: TObject);
begin
screen.cursor := crHourglass;
mnuSortBillToNo.checked := true;
mnuSortDateAscending.checked := false;
mnuSortDateDescending.checked := false;
qryARInv.close;
qryARInv.sql[0] := 'SELECT I.*, C.CustomerNo BillToNo, C.CustomerName BillToName, C.CurrencyID, C.Phone, C.EMail FROM ARInv I INNER JOIN Customer C ON I.BillToID = C.CustomerID';
qryARInv.sql[2] := 'ORDER BY C.BillToNo, I.InvoiceDate, I.InvoiceNo';
qryARInv.open;
screen.cursor := crDefault;
end;
procedure TfrmARInvoices.mnuSortInvoicenoClick(Sender: TObject);
begin
screen.cursor := crHourglass;
mnuSortInvoiceno.checked := true;
mnuSortDateAscending.checked := false;
mnuSortDateDescending.checked := false;
qryARInv.close;
qryARInv.sql[0] := 'SELECT I.*, C.CustomerNo BillToNo, C.CustomerName BillToName, C.CurrencyID, C.Phone, C.EMail FROM ARInv I INNER JOIN Customer C ON I.BillToID = C.CustomerID';
qryARInv.sql[2] := 'ORDER BY I.InvoiceNo, C.BillToName';
qryARInv.open;
screen.cursor := crDefault;
end;
procedure TfrmARInvoices.mnuBillToClick(Sender: TObject);
begin
if qryARInvBillToID.AsVariant = null then exit; //Bypass if no record selected (eg. if no records).
screen.cursor := crHourglass;
application.createform (TfrmCustomer,frmCustomer);
if (frmCustomer.tblCustomer.Locate('CustomerID', qryARInvBillToID.value, [])) = true then frmCustomer.Show;
screen.cursor := crDefault;
end;
procedure TfrmARInvoices.editFindInvoiceKeyPress(Sender: TObject; var Key: Char);
begin
if key = #13 then begin
Key := #0; //Cancel Enter key.
if (editFindInvoice.Text = '') or (editFindInvoice.Text = '<Invoice no.>') then begin
Perform(WM_NEXTDLGCTL, 0, 0); //Advance to next control.
exit;
end;
if (editFindCustomer.Text <> '') and (editFindCustomer.Text <> '<Bill-to no.>') then begin
if qryARInv.Locate('BillToNo;InvoiceNo', VarArrayOf([editFindCustomer.Text,editFindInvoice.Text]), []) <> true then begin
editFindInvoice.SelectAll;
raise(Exception.Create('Invoice ' + '''' + editFindInvoice.Text + '''' + ' not found for bill-to ' + '''' + editFindCustomer.Text + ''''));
end else DBGrid1.setfocus;
end else if (cboFindCustomer.Text <> '') and (cboFindCustomer.Text <> '<Bill-to name>') then begin
if qryARInv.Locate('BillToID;InvoiceNo', VarArrayOf([cboFindCustomer_CustomerIDs[cboFindCustomer.ItemIndex],editFindInvoice.Text]), []) <> true then begin
editFindInvoice.SelectAll;
raise(Exception.Create('Invoice ' + '''' + editFindInvoice.Text + '''' + ' not found for bill-to ' + '''' + cboFindCustomer.Text + ''''));
end else DBGrid1.setfocus;
end else editFindCustomer.setfocus;
end;
end;
procedure TfrmARInvoices.FormResize(Sender: TObject);
begin
if (WindowState <> OldWindowState) //Prevent grid resize bugs.
and (WindowState <> wsMinimized)
and (OldWindowState <> wsMinimized)
then mnuRefreshClick(sender);
OldWindowState := WindowState;
end;
procedure TfrmARInvoices.mnuPostClick(Sender: TObject);
begin
screen.cursor := crHourglass;
application.createform (TfrmARInvoicesPost,frmARInvoicesPost);
screen.cursor := crDefault;
if frmARInvoicesPost.ShowModal = mrOk then begin //Show invoices post form & if posting done, show JVs post form.
screen.cursor := crHourglass;
application.createform (TfrmJVsPost,frmJVsPost);
screen.cursor := crDefault;
if frmJVsPost.qryJV.RecordCount = 0 then frmJVsPost.close
else frmJVsPost.ShowModal;
mnuRefreshClick(sender);
end;
end;
procedure TfrmARInvoices.mnuFilterClick(Sender: TObject);
var
aComponent: TComponent;
begin
aComponent := Application.FindComponent('frmARInvoicesFilter');
if not Assigned (aComponent) then frmARInvoicesFilter := TfrmARInvoicesFilter.Create(Application);
frmARInvoicesFilter.ShowModal;
end;
procedure TfrmARInvoices.qryARInvFilterRecord(DataSet: TDataSet;
var Accept: Boolean);
begin
Accept := true; //Default.
try //Try in case filter form not loaded.
if (frmARInvoicesFilter.optPostedYes.checked = true) and (qryARInvPosted.value <> true) then Accept := false
else if (frmARInvoicesFilter.optPostedNo.checked = true) and (qryARInvPosted.value <> false) then Accept := false;
if (frmARInvoicesFilter.CurrencyID > 0) and (qryARInvCurrencyID.value <> frmARInvoicesFilter.CurrencyID) then Accept := false;
if (frmARInvoicesFilter.CustomerID > 0) and (qryARInvBillToID.value <> frmARInvoicesFilter.CustomerID) then Accept := false;
except; end;
end;
procedure TfrmARInvoices.mnuPrintClick(Sender: TObject);
var
strWHERE: string;
begin
//if license = '' then begin frmBS1.FreewareMessage; exit; end;
screen.cursor := crHourglass;
application.createform (TrptARInvoices,rptARInvoices);
rptARInvoices.qryARInv.SQL := frmARInvoices.qryARInv.SQL;
{if mnuFilter.checked = true then begin
strWHERE := ' WHERE (1 = 1)';
try //Try in case filter form not loaded.
if (frmARInvoicesFilter.optPostedYes.checked = true) then strWHERE := strWHERE + ' AND (Posted = true)'
else if (frmARInvoicesFilter.optPostedNo.checked = true) then strWHERE := strWHERE + ' AND (Posted = false)';
if (frmARInvoicesFilter.CurrencyID > 0) then strWHERE := strWHERE + ' AND (CurrencyID = ' + IntToStr(frmARInvoicesFilter.CurrencyID) + ')';
if (frmARInvoicesFilter.CustomerID > 0) then strWHERE := strWHERE + ' AND (BillToID = ' + IntToStr(frmARInvoicesFilter.CustomerID) + ')';
except; end;
rptARInvoices.qryARInv.SQL[0] := rptARInvoices.qryARInv.SQL[0] + strWHERE;
end;}
if mnuFilter.checked = true then begin
if rptARInvoices.qryARInv.SQL[1] = '' then rptARInvoices.qryARInv.SQL[1] := ' WHERE (1 = 1)';
try //Try in case filter form not loaded.
if (frmARInvoicesFilter.optPostedYes.checked = true) then rptARInvoices.qryARInv.SQL[1] := rptARInvoices.qryARInv.SQL[1] + ' AND (Posted = true)'
else if (frmARInvoicesFilter.optPostedNo.checked = true) then rptARInvoices.qryARInv.SQL[1] := rptARInvoices.qryARInv.SQL[1] + ' AND (Posted = false)';
if (frmARInvoicesFilter.CurrencyID > 0) then rptARInvoices.qryARInv.SQL[1] := rptARInvoices.qryARInv.SQL[1] + ' AND (CurrencyID = ' + IntToStr(frmARInvoicesFilter.CurrencyID) + ')';
if (frmARInvoicesFilter.CustomerID > 0) then rptARInvoices.qryARInv.SQL[1] := rptARInvoices.qryARInv.SQL[1] + ' AND (BillToID = ' + IntToStr(frmARInvoicesFilter.CustomerID) + ')';
except; end;
end;
if mnuOutstanding.checked = true then rptARInvoices.QuickReport.ReportTitle := 'AR Invoices (Outstanding)';
rptARInvoices.qryARInv.Active := true;
screen.cursor := crDefault;
rptARInvoices.QuickReport.Preview;
end;
procedure TfrmARInvoices.mnuPaymentsClick(Sender: TObject);
begin
if qryARInvARInvoiceID.AsVariant = null then exit; //Bypass if no record selected (eg. if no records).
screen.cursor := crHourglass;
application.createform (TfrmARInvoicePayments,frmARInvoicePayments);
frmARInvoicePayments.Show;
screen.cursor := crDefault;
end;
procedure TfrmARInvoices.popPhoneClick(Sender: TObject);
begin
with frmDialer do begin
NameToDial := qryARInvBillToName.value;
NumberToDial := qryARInvPhone.value;
ShowModal;
end;
end;
procedure TfrmARInvoices.mnuShipToClick(Sender: TObject);
begin
if qryARInvCustomerID.AsVariant = null then exit; //Bypass if no record selected (eg. if no records).
screen.cursor := crHourglass;
application.createform (TfrmCustomer,frmCustomer);
if (frmCustomer.tblCustomer.Locate('CustomerID', qryARInvCustomerID.value, [])) = true then frmCustomer.Show;
screen.cursor := crDefault;
end;
procedure TfrmARInvoices.mnuPrintInvoicesClick(Sender: TObject);
begin
//if license = '' then begin frmBS1.FreewareMessage; exit; end;
screen.cursor := crHourglass;
application.createform (TfrmARInvoicesPrint,frmARInvoicesPrint);
screen.cursor := crDefault;
if frmARInvoicesPrint.ShowModal = mrOk then mnuRefreshClick(sender);
end;
procedure TfrmARInvoices.mnuOutstandingClick(Sender: TObject);
begin
screen.cursor := crHourglass;
if mnuOutstanding.checked = true then begin
mnuOutstanding.checked := false;
if mnuFilter.checked = true then caption := 'AR Invoices (Filtered)'
else caption := 'AR Invoices';
qryARInv.close; qryARInv.SQL[1] := ''; qryARInv.open;
end else begin
mnuOutstanding.checked := true;
if mnuFilter.checked = true then caption := 'AR Invoices (Outstanding, Filtered)'
else caption := 'AR Invoices (Outstanding)';
qryARInv.close; qryARInv.SQL[1] := 'WHERE I.Owing <> 0'; qryARInv.open;
end;
screen.cursor := crDefault;
end;
procedure TfrmARInvoices.mnuARInvoicesHelpClick(Sender: TObject);
begin
Application.HelpContext(220);
end;
procedure TfrmARInvoices.FormClose(Sender: TObject;
var Action: TCloseAction);
begin
screen.cursor := crHourglass;
application.createform (TfrmARInvoicesPost,frmARInvoicesPost);
screen.cursor := crDefault;
if frmARInvoicesPost.qryARInv.RecordCount = 0 then begin
frmARInvoicesPost.close;
exit;
end;
//if frmARInvoicesPost.ShowModal = mrOk then mnuRefreshClick(sender);
if frmARInvoicesPost.ShowModal = mrOk then begin //Show invoices post form & if posting done, show JVs post form.
screen.cursor := crHourglass;
application.createform (TfrmJVsPost,frmJVsPost);
screen.cursor := crDefault;
if frmJVsPost.qryJV.RecordCount = 0 then frmJVsPost.close
else frmJVsPost.ShowModal;
end;
end;
procedure TfrmARInvoices.popEMailClick(Sender: TObject);
var
zFileName, zParams, zDir: array[0..79] of Char;
begin
ShellExecute(Application.MainForm.Handle, nil,
StrPCopy(zFileName, 'mailto:' + qryARInvEMail.value), {filename}
StrPCopy(zParams, ' '), {command line perameters}
StrPCopy(zDir, ''), {default directory}
SW_SHOW); {SW_SHOW Normal window. or SW_SHOWMINIMIZED, SW_HIDE, etc}
end;
procedure TfrmARInvoices.dsARInvDataChange(Sender: TObject; Field: TField);
begin
if qryARInvPhone.AsString = '' then popPhone.Enabled := False
else popPhone.Enabled := True;
if qryARInvEMail.AsString = '' then popEMail.Enabled := False
else popEMail.Enabled := True;
end;
procedure TfrmARInvoices.mnuPrintInvoiceClick(Sender: TObject);
begin
if qryARInvARInvoiceID.AsVariant = null then exit; //Bypass if no record selected (eg. if no records).
screen.cursor := crHourglass;
application.createform (TfrmARInvoicesPrint,frmARInvoicesPrint);
frmARInvoicesPrint.qryARInv.SQL[6] := 'WHERE I.ARInvoiceID = ' + qryARInvARInvoiceID.AsString;
frmARInvoicesPrint.OpenQuery;
if qryARInvPrinted.value = true then frmARInvoicesPrint.caption := 'Reprint AR Invoice ' + qryARInvInvoiceNo.AsString
else frmARInvoicesPrint.caption := 'Print AR Invoice ' + qryARInvInvoiceNo.AsString;
screen.cursor := crDefault;
if frmARInvoicesPrint.ShowModal = mrOk then mnuRefreshClick(sender);
end;
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -