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

📄 apchequenewform.pas

📁 功能全面的商业财会系统源码,清晰,很有参考价值.扩展性强.
💻 PAS
📖 第 1 页 / 共 2 页
字号:
      ProgressBar1.max := NumberOfInvoices;
      ProgressBar1.step := 1;
      repeat   //Exclusive open to prevent locking Delphi 2 locking bug.
      try
        tblAPChqCtl.Active := True;
        Break;   //If no error, exit the loop.
      except
        on EDatabaseError do if MessageDlg('Unable to open AP Cheque Control table exclusively.', mtError, [mbRetry, mbCancel], 0) <> mrRetry then raise;
      end;
      until False;
      tblAPCheq.Active := true;
      tblAPInvChq.Active := true;
      qryAPInv.First;
      while not qryAPInv.EOF do begin

        if (NumberOfCheques = 0) or (qryAPInvVendorID.value <> LastChequeVendorID) then begin   //On 1st invoice or vendor change, create new cheque.
          if LastChequeAmount < 0 then begin tblAPCheq.delete; NumberOfCheques := NumberOfCheques -1; end;
          try   //Create cheque.
            tblAPCheq.Insert;
              tblAPChqCtl.Edit;
              tblAPCheqChequeID.Value := tblAPChqCtlNextChequeID.Value;
              tblAPChqCtlNextChequeID.Value := tblAPChqCtlNextChequeID.Value + 1;
              tblAPChqCtl.Post;
            tblAPCheqChequeNo.AsVariant := null;
            tblAPCheqVendorID.value := qryAPInvVendorID.value;
            tblAPCheqBankID.value := BankID;
            tblAPCheqGLYear.value := GLYear;
            tblAPCheqGLPeriod.value := GLPeriod;
            tblAPCheqChequeDate.value := ChequeDate;
            tblAPCheqChequeAmount.value := 0;
            tblAPCheqReconciled.value := false;
            tblAPCheqPosted.value := false;
            tblAPCheqVoid.value := false;
            tblAPCheq.Post;
            NumberOfCheques := NumberOfCheques + 1;
            LastChequeVendorID := tblAPCheqVendorID.value;
            LastSeq := 0;
          except raise; end;
        end;

        try   //Create cheque detail.
          tblAPInvChq.Insert;
          tblAPInvChqAPInvoiceID.value := qryAPInvAPInvoiceID.value;
          tblAPInvChqChequeID.value := tblAPCheqChequeID.value;
          Inc(LastSeq);
          tblAPInvChqSeq.value := LastSeq;
          if (ChequeDate <= qryAPInvDiscountDate.value) and (qryAPInvDiscountTaken.value <> true) then tblAPInvChqPaymentAmount.AsCurrency := qryAPInvOwing.value - qryAPInvDiscountAmount.value
          else tblAPInvChqPaymentAmount.AsCurrency := qryAPInvOwing.value;
          tblAPInvChq.Post;
        except raise; end;

        try   //Update cheque amount.
          tblAPCheq.Edit;
          tblAPCheqChequeAmount.AsCurrency := tblAPCheqChequeAmount.value + tblAPInvChqPaymentAmount.value;
          tblAPCheq.Post;
          LastChequeAmount := tblAPCheqChequeAmount.AsCurrency;
        except raise; end;

        ProgressBar1.StepIt;
        qryAPInv.next;
      end;
      if LastChequeAmount < 0 then begin tblAPCheq.delete; NumberOfCheques := NumberOfCheques -1; end;
    end;
  finally
    DbiSaveChanges(tblAPChqCtl.handle);
    DbiSaveChanges(tblAPCheq.handle);
    DbiSaveChanges(tblAPInvChq.handle);
    tblAPChqCtl.Close;
    screen.cursor := crDefault;
    MessageDlg(IntToStr(NumberOfCheques) + ' cheque(s) were created.', mtInformation, [mbOK], 0);
  end;
end;

procedure TfrmAPChequeNew.btnCancelClick(Sender: TObject);
begin
  cboCurrency.ItemIndex := cboCurrencyIDs.IndexOf(CurrencyIDOld);
  cboVendor.ItemIndex := cboVendorIDs.IndexOf(VendorIDOld);
  DueDate := DueDateOld;
  ChequeDate := ChequeDateOld;
  GLPeriod := GLPeriodOld;
  GLYear := GLYearOld;
  if optSingleChequeCheckedOld = true then begin
    optSingleCheque.checked := true;
    optSingleCheque.setfocus;
  end else begin
    optAutoCreate.checked := true;
    optAutoCreate.setfocus;
  end;
end;

procedure TfrmAPChequeNew.FormShow(Sender: TObject);
begin
  ProgressBar1.position := 0;
  ProgressBar1.visible := false;

  if cboCurrency.ItemIndex > -1 then CurrencyIDOld := cboCurrencyIDs[cboCurrency.ItemIndex]
  else begin
    if frmBS1.tblCompanyDefaultCurrencyID.value > 0 then CurrencyIDOld := frmBS1.tblCompanyDefaultCurrencyID.AsString
    else CurrencyIDOld := '';
  end;
  if cboVendor.ItemIndex > -1 then VendorIDOld := cboVendorIDs[cboVendor.ItemIndex]
  else VendorIDOld := '';
  optSingleChequeCheckedOld := optSingleCheque.checked;
  optAutoCreateCheckedOld := optAutoCreate.checked;
  DueDateOld := DueDate;
  ChequeDateOld := ChequeDate;
  GLPeriodOld := GLPeriod;
  GLYearOld := GLYear;
  editDueDate.text := FormatDateTime('dd mmm yy', DueDate);
  editChequeDate.text := FormatDateTime('dd mmm yy', ChequeDate);
  editGLPeriod.text := IntToStr(GLPeriod);
  editGLYear.text := IntToStr(GLYear);

  cboCurrency_Load(dmLookUps.tblCurrency, cboCurrency);   //Populate "currency" combobox.
  cboVendor_Load(dmLookUps.tblVendor, cboVendor);   //Populate "vendor" combobox.
end;

procedure TfrmAPChequeNew.FormCreate(Sender: TObject);
var
  Year, Month, Day: word;
begin
  //tblCurrency.DatabaseName := strDatabaseName;   //Data Module used instead.
  //tblVendor.DatabaseName := strDatabaseName;   //Data Module used instead.
  qryAPInv.DatabaseName := strDatabaseName;
  tblAPCheq.DatabaseName := strDatabaseName;
  tblAPInvChq.DatabaseName := strDatabaseName;
  tblAPChqCtl.DatabaseName := strDatabaseName;
  //tblCurrency.Active := true;   //Data Module used instead.
  //tblVendor.Active := true;   //Data Module used instead.
  cboCurrencyIDs := TStringList.create;   //Create a TStringList to store CurrencyIDs for the combobox.
  cboVendorIDs := TStringList.create;   //Create a TStringList to store VendorIDs for the combobox.
  
  DueDate := Date;
  ChequeDate := Date;
  DecodeDate(Date, Year, Month, Day);
  if frmBS1.tblCompanyDefaultPeriodPP.value > 0 then GLPeriod := frmBS1.tblCompanyDefaultPeriodPP.value
  else                                               GLPeriod := Month;
  if frmBS1.tblCompanyDefaultPeriodYYYY.value > 0 then GLYear := frmBS1.tblCompanyDefaultPeriodYYYY.value
  //else if frmBS1.tblCompanyFiscalYear.value > 0 then GLYear := frmBS1.tblCompanyFiscalYear.value
  else                                                 GLYear := Year;
end;

procedure TfrmAPChequeNew.cboCurrencyExit(Sender: TObject);
begin
  if (cboCurrency.Items.count > 0) and (cboCurrency.Items.IndexOf(cboCurrency.Text) < 0) then begin
    cboCurrency.setfocus;
    raise(Exception.Create('Choose an item from the list'));
  end;
end;

procedure TfrmAPChequeNew.cboVendorExit(Sender: TObject);
begin
  if cboVendor.Items.IndexOf(cboVendor.Text) < 0 then begin
    cboVendor.setfocus;
    raise(Exception.Create('Choose an item from the list'));
  end;
end;

procedure TfrmAPChequeNew.optAutoCreateClick(Sender: TObject);
begin
  if optAutoCreate.checked = true then begin
    Groupbox1.enabled := true;
    cboCurrency.color := clWindow;
    cboVendor.color := clWindow;
    editDueDate.color := clWindow;
    editChequeDate.color := clWindow;
    editGLPeriod.color := clWindow;
    editGLYear.color := clWindow;
  end;
end;

procedure TfrmAPChequeNew.optSingleChequeClick(Sender: TObject);
begin
  if optSingleCheque.checked = true then begin
    Groupbox1.enabled := false;
    cboCurrency.color := clSilver;
    cboVendor.color := clSilver;
    editDueDate.color := clSilver;
    editChequeDate.color := clSilver;
    editGLPeriod.color := clSilver;
    editGLYear.color := clSilver;
  end;
end;

procedure TfrmAPChequeNew.btnDueDateClick(Sender: TObject);
begin
  if screen.ActiveControl.name = 'editDueDate' then SetDueDate(DueDate, editDueDate);   //If on date and it was changed, this hasn't been done yet.
  frmCalendar.caption := 'Due Date';
  if DueDate > StrToDate('01' + DateSeparator + '01' + DateSeparator + '1900') then frmCalendar.date := DueDate
  else frmCalendar.date := Date;
  if frmCalendar.ShowModal = mrOk then DueDate := frmCalendar.Date;
  editDueDateEnter(Sender);
  editDueDate.setfocus;
  //editDueDate.SelectAll;
end;

procedure TfrmAPChequeNew.editDueDateEnter(Sender: TObject);
begin
  editDueDate.EditMask := '!99/99/00;1;_';
  editDueDate.text := DateToStr(DueDate);
  editDueDate.SelectAll;
end;

procedure TfrmAPChequeNew.editDueDateExit(Sender: TObject);
begin
  SetDueDate(DueDate, editDueDate);
  editDueDate.EditMask := '';
  editDueDate.text := FormatDateTime('dd mmm yy', DueDate);
end;

procedure TfrmAPChequeNew.editDueDateKeyPress(Sender: TObject;
  var Key: Char);
begin
  if Key = ^J then begin   //Ctrl+Enter show calendar.
    btnDueDateClick(sender);
    Key := #0;
  end else if Key = '+' then begin   //Increase/decrease date via +/- keys.
    SetDueDate(DueDate, editDueDate);   //Update date for any changes keyed.
    if DueDate < StrToDate('01' + DateSeparator + '01' + DateSeparator + '1900') then DueDate := Date;
    DueDate := DueDate + 1;
    editDueDate.text := DateToStr(DueDate);
    key := #0;
  end else if Key = '-' then begin
    SetDueDate(DueDate, editDueDate);   //Update date for any changes keyed.
    if DueDate < StrToDate('01' + DateSeparator + '01' + DateSeparator + '1900') then DueDate := Date;
    DueDate := DueDate - 1;
    editDueDate.text := DateToStr(DueDate);
    key := #0;
  end;
end;

procedure TfrmAPChequeNew.btnChequeDateClick(Sender: TObject);
begin
  if screen.ActiveControl.name = 'editChequeDate' then SetChequeDate(ChequeDate, editChequeDate);   //If on date and it was changed, this hasn't been done yet.
  frmCalendar.caption := 'Cheque Date';
  if ChequeDate > StrToDate('01' + DateSeparator + '01' + DateSeparator + '1900') then frmCalendar.date := ChequeDate
  else frmCalendar.date := Date;
  if frmCalendar.ShowModal = mrOk then ChequeDate := frmCalendar.Date;
  editChequeDateEnter(Sender);
  editChequeDate.setfocus;
  //editChequeDate.SelectAll;
end;

procedure TfrmAPChequeNew.editChequeDateEnter(Sender: TObject);
begin
  editChequeDate.EditMask := '!99/99/00;1;_';
  editChequeDate.text := DateToStr(ChequeDate);
  editChequeDate.SelectAll;
end;

procedure TfrmAPChequeNew.editChequeDateExit(Sender: TObject);
begin
  SetChequeDate(ChequeDate, editChequeDate);
  editChequeDate.EditMask := '';
  editChequeDate.text := FormatDateTime('dd mmm yy', ChequeDate);
end;

procedure TfrmAPChequeNew.editChequeDateKeyPress(Sender: TObject;
  var Key: Char);
begin
  if Key = ^J then begin   //Ctrl+Enter show calendar.
    btnChequeDateClick(sender);
    Key := #0;
  end else if Key = '+' then begin   //Increase/decrease date via +/- keys.
    SetChequeDate(ChequeDate, editChequeDate);   //Update date for any changes keyed.
    if ChequeDate < StrToDate('01' + DateSeparator + '01' + DateSeparator + '1900') then ChequeDate := Date;
    ChequeDate := ChequeDate + 1;
    editChequeDate.text := DateToStr(ChequeDate);
    key := #0;
  end else if Key = '-' then begin
    SetChequeDate(ChequeDate, editChequeDate);   //Update date for any changes keyed.
    if ChequeDate < StrToDate('01' + DateSeparator + '01' + DateSeparator + '1900') then ChequeDate := Date;
    ChequeDate := ChequeDate - 1;
    editChequeDate.text := DateToStr(ChequeDate);
    key := #0;
  end;
end;

procedure TfrmAPChequeNew.editGLPeriodEnter(Sender: TObject);
begin
  editGLPeriod.text := IntToStr(GLPeriod);
  editGLPeriod.SelectAll;
end;

procedure TfrmAPChequeNew.editGLPeriodExit(Sender: TObject);
begin
  SetGLPeriod(GLPeriod, editGLPeriod);
end;

procedure TfrmAPChequeNew.editGLYearEnter(Sender: TObject);
begin
  editGLYear.text := Copy(IntToStr(GLYear),3,2);   //If editing, show last 2 digits of year.
  editGLYear.SelectAll;
end;

procedure TfrmAPChequeNew.editGLYearExit(Sender: TObject);
begin
  SetGLYear(GLYear, editGLYear);
  editGLYear.text := IntToStr(GLYear);
end;

procedure TfrmAPChequeNew.tblAPCheqBeforeDelete(DataSet: TDataSet);
begin
  with tblAPInvChq do begin   //Delete detail for this cheque.
    First;
    while not eof do Delete;
  end;
end;

end.

⌨️ 快捷键说明

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