⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 apchequenewform.pas

📁 功能全面的商业财会系统源码,清晰,很有参考价值.扩展性强.
💻 PAS
📖 第 1 页 / 共 2 页
字号:
unit APChequeNewForm;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  StdCtrls, ExtCtrls, Buttons, DB, DBTables, DBCtrls, Mask, ComCtrls, BDE;

type
  TfrmAPChequeNew = class(TForm)
    RadioGroup1: TRadioGroup;
    optSingleCheque: TRadioButton;
    optAutoCreate: TRadioButton;
    btnOK: TButton;
    btnCancel: TButton;
    GroupBox1: TGroupBox;
    cboVendor: TComboBox;
    Label2: TLabel;
    cboCurrency: TComboBox;
    Label1: TLabel;
    btnDueDate: TSpeedButton;
    Label3: TLabel;
    editDueDate: TMaskEdit;
    Label4: TLabel;
    editChequeDate: TMaskEdit;
    btnChequeDate: TSpeedButton;
    lblGLPeriod: TLabel;
    editGLPeriod: TEdit;
    editGLYear: TEdit;
    tblAPCheq: TTable;
    tblAPInvChq: TTable;
    tblAPInvChqAPInvoiceID: TIntegerField;
    tblAPInvChqChequeID: TIntegerField;
    tblAPInvChqSeq: TIntegerField;
    tblAPInvChqPaymentAmount: TCurrencyField;
    tblAPCheqChequeID: TIntegerField;
    tblAPCheqChequeNo: TIntegerField;
    tblAPCheqVendorID: TIntegerField;
    tblAPCheqBankID: TIntegerField;
    tblAPCheqGLYear: TSmallintField;
    tblAPCheqGLPeriod: TSmallintField;
    tblAPCheqChequeDate: TDateField;
    tblAPCheqChequeAmount: TCurrencyField;
    tblAPCheqReconciled: TBooleanField;
    tblAPCheqPosted: TBooleanField;
    tblAPCheqVoid: TBooleanField;
    qryAPInv: TQuery;
    ProgressBar1: TProgressBar;
    tblAPChqCtl: TTable;
    tblAPChqCtlNextChequeID: TIntegerField;
    qryAPInvAPInvoiceID: TIntegerField;
    qryAPInvVendorID: TIntegerField;
    qryAPInvDiscountDate: TDateField;
    qryAPInvDiscountAmount: TCurrencyField;
    qryAPInvDiscountTaken: TBooleanField;
    qryAPInvOwing: TCurrencyField;
    dsAPCheq: TDataSource;
    procedure btnOKClick(Sender: TObject);
    procedure btnCancelClick(Sender: TObject);
    procedure FormShow(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure cboCurrencyExit(Sender: TObject);
    procedure cboVendorExit(Sender: TObject);
    procedure optAutoCreateClick(Sender: TObject);
    procedure optSingleChequeClick(Sender: TObject);
    procedure btnDueDateClick(Sender: TObject);
    procedure editDueDateEnter(Sender: TObject);
    procedure editDueDateExit(Sender: TObject);
    procedure editDueDateKeyPress(Sender: TObject; var Key: Char);
    procedure btnChequeDateClick(Sender: TObject);
    procedure editChequeDateEnter(Sender: TObject);
    procedure editChequeDateExit(Sender: TObject);
    procedure editChequeDateKeyPress(Sender: TObject; var Key: Char);
    procedure editGLPeriodEnter(Sender: TObject);
    procedure editGLPeriodExit(Sender: TObject);
    procedure editGLYearEnter(Sender: TObject);
    procedure editGLYearExit(Sender: TObject);
    procedure tblAPCheqBeforeDelete(DataSet: TDataSet);
  private
    procedure SetCurrencyID(CurrencyID: integer);
    function GetCurrencyID: integer;
    procedure SetVendorID(VendorID: integer);
    function GetVendorID: integer;
  public
    property CurrencyID: integer read GetCurrencyID write SetCurrencyID;
    property VendorID: integer read GetVendorID write SetVendorID;
  end;

var
  frmAPChequeNew: TfrmAPChequeNew;

implementation

uses BS1Form, APChequeForm, LookUpsData, CalendarForm;

{$R *.DFM}

var
  CurrencyIDOld, VendorIDOld: string;
  optSingleChequeCheckedOld, optAutoCreateCheckedOld: Boolean;
  cboCurrencyIDs, cboVendorIDs: TStringList;
  DueDate, ChequeDate, DueDateOld, ChequeDateOld: TDateTime;
  GLPeriod, GLYear, GLPeriodOld, GLYearOld: integer;

procedure TfrmAPChequeNew.SetCurrencyID(CurrencyID: integer);
begin
  CboCurrency.ItemIndex := cboCurrencyIDs.IndexOf(IntToStr(CurrencyID));
end;

function TfrmAPChequeNew.GetCurrencyID: integer;
begin
  if cboCurrency.ItemIndex > -1 then Result := StrToInt(cboCurrencyIDs[cboCurrency.ItemIndex])
  else Result := 0;
end;

procedure TfrmAPChequeNew.SetVendorID(VendorID: integer);
begin
  CboVendor.ItemIndex := cboVendorIDs.IndexOf(IntToStr(VendorID));
end;

function TfrmAPChequeNew.GetVendorID: integer;
begin
  if cboVendor.ItemIndex > 0 then Result := StrToInt(cboVendorIDs[cboVendor.ItemIndex])
  else Result := 0;
end;

procedure cboCurrency_Load(const Tbl: TTable; const Cbo: TCombobox);
begin
  Cbo.Items.Clear;   //Populate "currency" combobox.
  cboCurrencyIDs.Clear;
  Tbl.First;
  while not Tbl.EOF do begin
    Cbo.Items.Add(Tbl['CurrencyName']);
    cboCurrencyIDs.Add(Tbl['CurrencyID']);
    Tbl.Next;
  end;
  Cbo.ItemIndex := cboCurrencyIDs.IndexOf(CurrencyIDOld);
end;

procedure cboVendor_Load(const Tbl: TTable; const Cbo: TCombobox);
begin
  Cbo.Items.Clear;   //Populate "vendor" combobox.
  cboVendorIDs.Clear;
  Cbo.Items.Add('<All>');
  cboVendorIDs.Add('');
  Tbl.First;
  while not Tbl.EOF do begin
    Cbo.Items.Add(Tbl['VendorName']);
    cboVendorIDs.Add(Tbl['VendorID']);
    Tbl.Next;
  end;
  Cbo.ItemIndex := cboVendorIDs.IndexOf(VendorIDOld);
  //Cbo.ItemIndex := 0;   //Reset.
end;

procedure SetDueDate(var DueDate: TDateTime; var editDueDate: TMaskEdit);
var
  Year, Month, Day: Word;
begin
  try
    DueDate := StrToDate(editDueDate.text);
    DecodeDate(DueDate, Year, Month, Day);
    if (Year < 1950) and (Year > 1899) then begin
      Year := Year + 100;
      DueDate := EncodeDate(Year,Month,Day);
    end else if (Year > 2050) then begin
      Year := Year - 100;
      DueDate := EncodeDate(Year,Month,Day);
    end;
  except;
    if (editDueDate.text = ' 2' + DateSeparator + '29' + DateSeparator + '00') or (editDueDate.text = '02' + DateSeparator + '29' + DateSeparator + '00') then DueDate := StrToDate('02' + DateSeparator + '29' + DateSeparator + '2000')
    else if (editDueDate.text = '29' + DateSeparator + '02' + DateSeparator + '00') then DueDate := StrToDate('29' + DateSeparator + '02' + DateSeparator + '2000')
    else begin
      editDueDate.setfocus;
      raise;
    end;
  end;
end;

procedure SetChequeDate(var ChequeDate: TDateTime; var editChequeDate: TMaskEdit);
var
  Year, Month, Day: Word;
begin
  try
    ChequeDate := StrToDate(editChequeDate.text);
    DecodeDate(ChequeDate, Year, Month, Day);
    if (Year < 1950) and (Year > 1899) then begin
      Year := Year + 100;
      ChequeDate := EncodeDate(Year,Month,Day);
    end else if (Year > 2050) then begin
      Year := Year - 100;
      ChequeDate := EncodeDate(Year,Month,Day);
    end;
  except;
    if (editChequeDate.text = ' 2' + DateSeparator + '29' + DateSeparator + '00') or (editChequeDate.text = '02' + DateSeparator + '29' + DateSeparator + '00') then ChequeDate := StrToDate('02' + DateSeparator + '29' + DateSeparator + '2000')
    else if (editChequeDate.text = '29' + DateSeparator + '02' + DateSeparator + '00') then ChequeDate := StrToDate('29' + DateSeparator + '02' + DateSeparator + '2000')
    else begin
      editChequeDate.setfocus;
      raise;
    end;
  end;
end;

procedure SetGLPeriod(var GLPeriod: integer; var editGLPeriod: TEdit);
var
  intWork: integer;
begin
  try intWork := StrToInt(editGLPeriod.text); except; editGLPeriod.text := '0'; end;   //Prevent error if can't convert text to integer.
  if (StrToInt(editGLPeriod.text) > 0) and (StrToInt(editGLPeriod.text) <= 12) then GLPeriod := StrToInt(editGLPeriod.text)
  else begin
    editGLPeriod.setfocus;
    editGLPeriod.SelectAll;
    raise(exception.create('Period must be between 1 and 12'));
  end;
end;

procedure SetGLYear(var GLYear: integer; var editGLYear: TEdit);
var
  intWork: integer;
begin
  try intWork := StrToInt(editGLYear.text); except; editGLYear.text := '0'; end;   //Prevent error if can't convert text to integer.
  if (StrToInt(editGLYear.text) < 0) or (StrToInt(editGLYear.text) > 99) then begin
    editGLYear.setfocus;
    editGLYear.SelectAll;
    raise(exception.create('Period invalid...' + #13 + 'Enter year as 2 digits'));
  end else if StrToInt(editGLYear.text) < 50 then GLYear := StrToInt(editGLYear.text) + 2000   //Convert 2 digit year to 4.
  else GLYear := StrToInt(editGLYear.text) + 1900;
end;

procedure TfrmAPChequeNew.btnOKClick(Sender: TObject);
var
  NumberOfCheques, NumberOfInvoices: integer;
  APCheqGLPeriodYYYYPP, EPeriodFromYYYYPP, EPeriodToYYYYPP, WPeriodFromYYYYPP, WPeriodToYYYYPP: integer;
  LookupResults: variant;
  BankID, LastChequeVendorID, LastSeq: integer;
  LastChequeAmount: currency;
begin
  if screen.ActiveControl.name = 'editDueDate' then SetDueDate(DueDate, editDueDate);   //If Enter was pressed, this hasn't been done yet.
  if screen.ActiveControl.name = 'editChequeDate' then SetChequeDate(ChequeDate, editChequeDate);   //If Enter was pressed, this hasn't been done yet.
  if screen.ActiveControl.name = 'editGLPeriod' then SetGLPeriod(GLPeriod, editGLPeriod);   //If Enter was pressed, this hasn't been done yet.
  if screen.ActiveControl.name = 'editGLYear' then SetGLYear(GLYear, editGLYear);   //If Enter was pressed, this hasn't been done yet.
  if (cboCurrency.Items.count > 0) and (cboCurrency.Items.IndexOf(cboCurrency.Text) < 0) then begin  //If Enter was pressed, this edit hasn't been done yet.
    cboCurrency.setfocus;
    raise(Exception.Create('Choose an item from the list'));
  end;
  if cboVendor.Items.IndexOf(cboVendor.Text) < 0 then begin  //If Enter was pressed, this edit hasn't been done yet.
    cboVendor.setfocus;
    raise(Exception.Create('Choose an item from the list'));
  end;
  if optAutoCreate.checked = true then begin
    APCheqGLPeriodYYYYPP := (GLYear * 100) + GLPeriod;
    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
      editGLPeriod.SetFocus;
      raise(exception.create('Current fiscal year is not yet defined...' + #13 + 'See "Your Company"'));
    end;
    if GLYear = 0 then begin
       editGLYear.SetFocus;
      raise(exception.create('Field ' + '''' + 'Year of Period' + '''' + ' must have a value'));
    end;
    if GLYear < frmBS1.tblCompanyFiscalYear.value then begin
      editGLPeriod.SetFocus;
      raise(exception.create('GL Period is prior to current fiscal year ' + #13 + 'as defined by "Your Company"'));
    end;
    if GLPeriod = 0 then begin
      editGLPeriod.SetFocus;
      raise(exception.create('Field ' + '''' + 'Period' + '''' + ' must have a value'));
    end;
    if (APCheqGLPeriodYYYYPP < EPeriodFromYYYYPP) or ((EPeriodToYYYYPP > 0) and (APCheqGLPeriodYYYYPP > EPeriodToYYYYPP)) then begin
      editGLPeriod.SetFocus;
      raise(exception.create('GL Period is not within allowed range ' + #13 + 'as defined by "Your Company"'));
    end;
    if (APCheqGLPeriodYYYYPP < WPeriodFromYYYYPP) or ((WPeriodToYYYYPP > 0) and (APCheqGLPeriodYYYYPP > 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
        editGLPeriod.SetFocus;
        raise(EAbort.create(''));  //Silent Exception: "abort;" replaced by "raise etc" since abort conflicts with BDE (required by DbiSaveChanges).
      end;
    end;
    dmLookUps.tblBank.Active := true;
    LookupResults := dmLookUps.tblBank.LookUp('CurrencyID', CurrencyID, 'BankID');
    if LookupResults = null then begin
      cboCurrency.Setfocus;
      raise(exception.create('No bank found for selected currency'));
    end else BankID := LookupResults;
  end;
  modalResult := mrOK;

  if optSingleCheque.Checked = true then optSingleCheque.setfocus
  else optAutoCreate.setfocus;


  if optAutoCreate.checked <> true then exit;
  NumberOfCheques := 0;
  LastChequeVendorID := 0;
  LastChequeAmount := 0;
  screen.cursor := crHourglass;
  try
    qryAPInv.close;
    qryAPInv.Params[0].AsDate := DueDate;
    qryAPInv.Params[1].AsInteger := CurrencyID;
    if VendorID >0 then begin
      qryAPInv.SQL[3] := 'and (V.VendorID=:VendorID)';
      qryAPInv.Params[2].AsInteger := VendorID;
    end else qryAPInv.SQL[3] := '';
    qryAPInv.open;
    NumberOfInvoices := qryAPInv.RecordCount;
    if NumberOfInvoices = 0 then modalResult := mrCancel
    else begin
      ProgressBar1.visible := true;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -