📄 arinvoiceform.pas
字号:
end else if TaxCode = tblARInvTaxableAmtCode3.value then begin
tblARInvTaxableAmount3.AsCurrency := tblARInvTaxableAmount3.value + Amount;
if tblARInvTaxableAmount3.value = 0 then tblARInvTaxableAmtCode3.AsVariant := null;
end else begin
if tblARInvTaxableAmtCode1.AsVariant = null then begin
tblARInvTaxableAmtCode1.value := TaxCode;
tblARInvTaxableAmount1.AsCurrency := Amount;
end else if tblARInvTaxableAmtCode2.AsVariant = null then begin
tblARInvTaxableAmtCode2.value := TaxCode;
tblARInvTaxableAmount2.AsCurrency := Amount;
end else if tblARInvTaxableAmtCode3.AsVariant = null then begin
tblARInvTaxableAmtCode3.value := TaxCode;
tblARInvTaxableAmount3.AsCurrency := Amount;
end else begin
raise(exception.create('Too many taxes...' +#13 +
'More than 3 tax codes were encountered while processing the items on this invoice. ' +#13 +
'Please check the items to ensure the tax codes are correct'));
end;
end;
end;
{procedure TfrmARInvoice.CalcTax(tblARInvTax1Code, tblARInvTax2Code, tblARInvTax1Description, tblARInvTax2Description, tblARInvTaxableAmtCode1,
tblARInvTaxableAmtCode2, tblARInvTaxableAmtCode3: TStringField; tblARInvTax1Rate, tblARInvTax2Rate: TFloatField; tblARInvTaxableAmount1, tblARInvTaxableAmount2, tblARInvTaxableAmount3: TCurrencyField);
begin
if tblARInvTax1Code.value = tblARInvTaxableAmtCode1.value then Tax1Amount := frmBS1.RoundIt(tblARInvTaxableAmount1.value * tblARInvTax1Rate.value)/100
else if tblARInvTax1Code.value = tblARInvTaxableAmtCode2.value then Tax1Amount := frmBS1.RoundIt(tblARInvTaxableAmount2.value * tblARInvTax1Rate.value)/100
else if tblARInvTax1Code.value = tblARInvTaxableAmtCode3.value then Tax1Amount := frmBS1.RoundIt(tblARInvTaxableAmount3.value * tblARInvTax1Rate.value)/100
else Tax1Amount := 0;
if tblARInvTax2Code.value = tblARInvTaxableAmtCode1.value then Tax2Amount := frmBS1.RoundIt(tblARInvTaxableAmount1.value * tblARInvTax2Rate.value)/100
else if tblARInvTax2Code.value = tblARInvTaxableAmtCode2.value then Tax2Amount := frmBS1.RoundIt(tblARInvTaxableAmount2.value * tblARInvTax2Rate.value)/100
else if tblARInvTax2Code.value = tblARInvTaxableAmtCode3.value then Tax2Amount := frmBS1.RoundIt(tblARInvTaxableAmount3.value * tblARInvTax2Rate.value)/100
else Tax2Amount := 0;
if Tax1Amount <> 0 then lblTaxes.caption := tblARInvTax1Description.value + ': ' + FloatToStrF(Tax1Amount,ffCurrency,18,2) + ' '
else lblTaxes.caption := '';
if Tax2Amount <> 0 then lblTaxes.caption := lblTaxes.caption + tblARInvTax2Description.value + ': ' + FloatToStrF(Tax2Amount,ffCurrency,18,2);
end;}
procedure TfrmARInvoice.btnOKClick(Sender: TObject);
begin
if tblARInv.State in [dsInsert, dsEdit] then tblARInv.post;
if tblARInvDet.State in [dsInsert, dsEdit] then tblARInvDet.post;
tblARInv.Database.ApplyUpdates([tblARInv, tblARInvDet]);
DbiSaveChanges(tblARInv.handle);
DbiSaveChanges(tblARInvDet.handle);
try
with frmARInvoices.qryARInv do begin close; open; end; //Refresh, etc.
frmARInvoices.qryARInv.Locate('ARInvoiceID', tblARInvARInvoiceID.value, []);
except; end;
if (tblARInv.UpdatesPending = false) and (tblARInvDet.UpdatesPending = false) then Close;
end;
procedure TfrmARInvoice.btnCancelClick(Sender: TObject);
begin
tblARInv.DisableControls;
tblARInv.cancel;
tblARInv.CancelUpdates;
tblARInvDet.cancel;
tblARInvDet.CancelUpdates;
Close;
end;
procedure TfrmARInvoice.FormCreate(Sender: TObject);
var
x: integer;
begin
tblARInv.DatabaseName := strDatabaseName;
tblARInvCtl.DatabaseName := strDatabaseName;
tblARInvDet.DatabaseName := strDatabaseName;
//tblCustomer.DatabaseName := strDatabaseName;
tblBillTo.DatabaseName := strDatabaseName;
//tblItem.DatabaseName := strDatabaseName;
qryLastDetailLineNo.DatabaseName := strDatabaseName;
tblARInv.Active := true;
tblARInvDet.Active := true;
//tblCustomer.Active := true; //Data Module used instead.
//tblItem.Active := true; //Data Module used instead.
tblARInv.Database.TransIsolation := tiDirtyRead;
if FontFactor <> 1 then begin //If using large fonts, resize form.
for x := 0 to DBGrid1.Columns.Count - 1 do DBGrid1.Columns[x].width := Trunc(DBGrid1.Columns[x].width*FontFactor);
ClientHeight := Trunc(ClientHeight*FontFactor);
ClientWidth := Trunc(ClientWidth*FontFactor);
end;
intClientHeight := ClientHeight; //Store form size.
intClientWidth := ClientWidth;
Tax1Amount := 0;
Tax2Amount := 0;
end;
procedure TfrmARInvoice.Panel2DblClick(Sender: TObject);
begin
ClientHeight := intClientHeight; //Resize form.
ClientWidth := intClientWidth;
end;
procedure TfrmARInvoice.FormClose(Sender: TObject; var Action: TCloseAction);
begin
if (tblARInv.State in [dsInsert, dsEdit]) or (tblARInvDet.State in [dsInsert, dsEdit])
or (tblARInv.UpdatesPending = true) or (tblARInvDet.UpdatesPending = true) then btnOKClick(sender);
try frmARInvoices.DBGrid1.Setfocus; except; end;
Action := caFree;
end;
procedure TfrmARInvoice.btnCustomerClick(Sender: TObject);
var
aComponent: TComponent;
begin
screen.cursor := crHourglass;
aComponent := Application.FindComponent('frmCustomers');
if Assigned (aComponent) then try frmCustomers.qryCustomer.close; frmCustomers.qryCustomer.open; except; end
else frmCustomers := TfrmCustomers.Create(Application);
aComponent := Application.FindComponent('frmCustomersFilter');
if Assigned (aComponent) then try frmCustomersFilter.btnResetClick(sender); except; end;
frmCustomers.mnuFilter.Checked := false;
frmCustomers.qryCustomer.Filtered := false;
frmCustomers.tblCustomer.Filtered := false;
if frmCustomers.WindowState = wsMinimized then frmCustomers.WindowState := wsNormal;
if frmCustomers.visible = true then frmCustomers.FormShow(sender)
else frmCustomers.Show;
if not frmCustomers.qryCustomer.Locate('CustomerID', tblARInvCustomerID.value, []) then frmCustomers.qryCustomer.First;
screen.cursor := crDefault;
end;
procedure TfrmARInvoice.FormKeyPress(Sender: TObject; var Key: Char);
begin
if key = #13 then begin //Enter key: advance to next control.
if not (ActiveControl is TDBGrid) and (ActiveControl.ClassType <> TDBMemo) and (ActiveControl.ClassType <> TDBLookupCombobox) then begin
Key := #0;
if (ActiveControl.name = 'editCustomerNo') and (editCustomerNo.text <> '') then editInvoiceDate.setfocus
else Perform(WM_NEXTDLGCTL, 0, 0);
end else if (ActiveControl.ClassType = TDBLookupComboBox) and (TDBLookupComboBox(ActiveControl).ListVisible = false) then begin
Key := #0;
Perform(WM_NEXTDLGCTL, 0, 0);
end else if (ActiveControl is TDBGrid) then begin
key := #0;
//Exit grid if on a new record & no data... replaced by ColExit event (as this event can't see whether data is being entered in the current cell).
//if (TDBGrid(ActiveControl).selectedindex = 1) and (tblARInvDetSeq.AsVariant = Null) and (tblARInvDetGLAmount.AsVariant = Null) then Perform(WM_NEXTDLGCTL, 0, 0)
//else}
with TDBGrid(ActiveControl) do
//if selectedindex < (fieldcount - 1) then //Increment the field.
if selectedindex = 3 then selectedindex := 5 //Increment the field + skip Extended Amount.
else if selectedindex < 5 then selectedindex := selectedindex + 1
else begin //Move to next record.
selectedindex := 0;
tblARInvDet.next;
if tblARInvDet.eof = true then tblARInvDet.append;
end;
end;
end;
end;
procedure TfrmARInvoice.DBGrid1ColExit(Sender: TObject);
begin //Exit grid if leaving 1st column on a new record & no data. Actually if leaving column 1 (to another cell in the grid), and target cell is a record with no Seq (new record) or GLAmount.
if (TDBGrid(ActiveControl).SelectedIndex = 0) and (tblARInvDetSeq.AsVariant = Null) and (tblARInvDetQuantity.AsVariant = Null) and (tblARInvDetItemNo.AsVariant = Null) and (tblARInvDetUnitPrice.AsVariant = Null) and (tblARInvDetItemOvDesc.AsVariant = Null) and (tblARInvDet.RecordCount > 0) then btnOK.setfocus;
end;
procedure TfrmARInvoice.FormKeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
begin
if (key = VK_Next) then begin //PageDown
key := 0;
if not (ActiveControl is TDBGrid) then begin //Move to 1st record on grid.
DBGrid1.Setfocus;
tblARInvDet.First;
DBGrid1.SelectedIndex := 0;
end else begin
tblARInvDet.append; //Move to new record on grid.
DBGrid1.SelectedIndex := 0;
end;
end;
end;
procedure TfrmARInvoice.DBGrid1Exit(Sender: TObject);
begin
DBGrid1.Options := [dgEditing,dgTitles,dgIndicator,dgColumnResize,dgColLines,dgRowLines,dgTabs,dgConfirmDelete,dgCancelOnExit]; //Toggle dgAlwaysShowEditor to prevent 1st field from being left-justified if always dgAlwaysShowEditor.
tblARInvDet.First;
DBGrid1.SelectedIndex := 0;
end;
procedure TfrmARInvoice.DBGrid1Enter(Sender: TObject);
begin
DBGrid1.SelectedIndex := 0; //Fix problem caused when ColExit event causes exit from grid with pending Enter setting selected index to 2nd column.
end;
procedure TfrmARInvoice.dsARInvUpdateData(Sender: TObject);
begin
if tblARInvCustomerID.AsVariant = null then begin
with editCustomerNo do begin Show; SetFocus; end;
raise(exception.create('Field ' + '''Ship-to''' + ' must have a value'));
end;
end;
procedure TfrmARInvoice.editInvoiceDateKeyPress(Sender: TObject;
var Key: Char);
begin
if Key = ^J then begin //Ctrl+Enter show calendar.
btnInvoiceDateClick(sender);
Key := #0;
end else if Key = '+' then begin //Increase/decrease date via +/- keys.
tblARInv.Edit;
if editInvoiceDate.field.AsVariant = null then editInvoiceDate.field.AsDateTime := Date;
editInvoiceDate.field.AsDateTime := editInvoiceDate.field.AsDateTime + 1;
key := #0;
end else if Key = '-' then begin
tblARInv.Edit;
if editInvoiceDate.field.AsVariant = null then editInvoiceDate.field.AsDateTime := Date;
editInvoiceDate.field.AsDateTime := editInvoiceDate.field.AsDateTime - 1;
key := #0;
end;
end;
procedure TfrmARInvoice.cboCustomerKeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
begin
if key = VK_Delete then begin
tblARInv.Edit;
tblARInvCustomerID.AsVariant := null;
end;
end;
procedure TfrmARInvoice.dsARInvDataChange(Sender: TObject; Field: TField);
begin
//if (tblARInv.state = dsInsert) and (tblARInvInvoiceNo.Value = '') then self.Caption := 'New Invoice' //Suppressed because default Invoice no. already assigned.
if (tblARInv.state = dsInsert) and ((tblARInvInvoiceNo.Value = '') or (tblARInvCustomerID.AsVariant = null)) then self.Caption := 'New Invoice'
else self.Caption := 'Invoice ' + tblARInvInvoiceNo.Value;
editCustomerNo.text := tblARInvCustomerNo.value;
editCustomerNo.ReadOnly := tblARInvPosted.value;
lblPosted.visible := tblARInvPosted.value;
if tblARInvCustomerID.AsVariant = null then begin
txtAddress.visible := false;
txtTerms.visible := false;
end else begin
txtAddress.visible := true;
txtTerms.visible := true;
end;
end;
procedure TfrmARInvoice.tblARInvInvoiceAmountChange(Sender: TField);
begin
tblARInvOwing.AsCurrency := tblARInvInvoiceAmount.value - tblARInvPaidAmount.value - tblARInvDiscTakenAmount.value - tblARInvWriteOffAmount.value;
end;
procedure TfrmARInvoice.DBGrid1KeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
begin
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -