📄 invoiceprintbrowsefrm.pas
字号:
unit InvoicePrintBrowseFrm;
interface
{$I InvPrinter.inc}
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, SJCustomBrowseFrm, wwDialog, wwfltdlg, ActnList, XPMenu, Menus,
PropStorageEh, Grids, DBGridEh, ExtCtrls, StdCtrls, cxControls, IniFiles,
cxContainer, cxEdit, cxTextEdit, cxMaskEdit, cxDBEdit, cxCheckBox,
cxDropDownEdit, cxCalendar, cxLookAndFeelPainters, cxButtons,
cxLookupEdit, cxDBLookupEdit, cxDBLookupComboBox, ImgList, fcLabel,
cxSpinEdit, RM_FormReport, RM_Desgn;
type
TfrmBrowseInvoicePrint = class(TSJCustomBrowseForm)
ControlPanel: TPanel;
Label1: TLabel;
edtCustID: TcxDBMaskEdit;
Label2: TLabel;
Label3: TLabel;
edtInvoice: TcxMaskEdit;
chkStopUpdateInvoice: TcxCheckBox;
Label4: TLabel;
edtPaydate: TcxDateEdit;
Label5: TLabel;
Label6: TLabel;
edtPriorQty: TcxDBMaskEdit;
Label7: TLabel;
edtDerate: TcxDBMaskEdit;
Label8: TLabel;
edtQty: TcxDBMaskEdit;
Label9: TLabel;
btnPrint: TcxButton;
chkShowall: TcxCheckBox;
chkSeriesPrint: TcxCheckBox;
actBrowseLoadSetting: TAction;
cxButton1: TcxButton;
actBrowsePrintSetting: TAction;
L1: TMenuItem;
actBrowseMonthChargeGroupReport: TAction;
T1: TMenuItem;
N6: TMenuItem;
edtName: TcxLookupComboBox;
actBrowsePrintInvoice: TAction;
edtCurrQty: TcxDBMaskEdit;
edtBigAmont: TcxDBMaskEdit;
InvoicePanel: TPanel;
Label10: TLabel;
edtCustomer: TcxLookupComboBox;
Label11: TLabel;
edtInvoiceNO: TcxMaskEdit;
spinYear: TcxSpinEdit;
Label12: TLabel;
spinMonth: TcxSpinEdit;
Label13: TLabel;
spinDay: TcxSpinEdit;
Label14: TLabel;
DBGridEh1: TDBGridEh;
Label18: TLabel;
edtCharge: TcxLookupComboBox;
Label19: TLabel;
Label20: TLabel;
edtCompany: TcxMaskEdit;
btnPrintInvoice: TcxButton;
chkSeriesPrint1: TcxCheckBox;
chkShowAll1: TcxCheckBox;
edtCollector: TcxLookupComboBox;
Panel1: TPanel;
BigAmontPanel: TPanel;
Bevel2: TBevel;
Panel2: TPanel;
Label15: TLabel;
Label16: TLabel;
Shape1: TShape;
AmontPanel: TPanel;
Splitter1: TSplitter;
Panel3: TPanel;
Label17: TLabel;
Bevel4: TBevel;
Shape2: TShape;
labBigAmont: TfcLabel;
fcLabel1: TfcLabel;
Label21: TLabel;
fcLabel2: TfcLabel;
actBrowseBlankoutInvoice: TAction;
B1: TMenuItem;
N7: TMenuItem;
R2: TMenuItem;
N8: TMenuItem;
actBrowseMonthChargeDetailReport: TAction;
procedure FormCreate(Sender: TObject);
procedure edtCustIDExit(Sender: TObject);
procedure chkShowallClick(Sender: TObject);
procedure FormShow(Sender: TObject);
procedure edtCustIDKeyPress(Sender: TObject; var Key: Char);
procedure actBrowsePrintExecute(Sender: TObject);
procedure actBrowsePrintSettingExecute(Sender: TObject);
procedure actBrowseLoadSettingExecute(Sender: TObject);
procedure actBrowseMonthChargeGroupReportExecute(Sender: TObject);
procedure edtNamePropertiesCloseUp(Sender: TObject);
procedure edtNamePropertiesInitPopup(Sender: TObject);
procedure DBGridEh1ColWidthsChanged(Sender: TObject);
procedure edtCustomerPropertiesChange(Sender: TObject);
procedure FormDestroy(Sender: TObject);
procedure actBrowseBlankoutInvoiceExecute(Sender: TObject);
private
FPrinting, FopPreview, FopShowDialog: Boolean;
FopInvoiceLength: Integer;
FopCompany, FopAddress, FopItem, FopUnits, FopCollector: string;
FopStartInv, FopEndInv, FopCurrInvoice: string;
procedure LocateRecord;
procedure LoadSetting;
procedure SaveCurrInvoice;
function PrepareData: Boolean;
public
property Item: string read FopItem;
property Units: string read FopUnits;
end;
var
frmBrowseInvoicePrint: TfrmBrowseInvoicePrint;
implementation
uses InvPrintDM, MainFrm, SJInvPrintGlobal, sjUtils, OptionsPropertyFrm,
BlankoutInvoicePropertyFrm, MonthStatReportDialogFrm;
{$R *.dfm}
procedure TfrmBrowseInvoicePrint.FormCreate(Sender: TObject);
begin
inherited;
FPrinting := False;
LoadSetting;
end;
procedure TfrmBrowseInvoicePrint.edtCustIDExit(Sender: TObject);
// 显示用户选定的客户未缴费资料
begin
inherited;
if not edtCustID.EditModified then
Exit;
LocateRecord;
end;
procedure TfrmBrowseInvoicePrint.chkShowallClick(Sender: TObject);
// 显示所有未打印发票的用水记录
begin
inherited;
if not {$IFDEF DJSR}chkShowAll1.Checked{$ELSE}chkShowAll.Checked{$ENDIF DJSR} then
with dmInvPrint.AqryPrint do
begin
Close;
SQL.Clear;
SQL.Add('select * from Waterfee where CustID = ''9999999999'' and Payflag = False');
Open;
Exit;
end;
with dmInvPrint.AqryPrint do
try
Screen.Cursor := crHourGlass;
Close;
SQL.Clear;
SQL.Add('select * from Waterfee where Payflag = False order by CustID, WRID');
try
Open;
except
ShowMessage('打开未打印发票的客户用水资料时失败,请稍后再试 。');
Exit;
end;
if not IsEmpty then
btnPrint.SetFocus
else
ShowMessage('当前还没有未打印发票的用水记录 。');
actBrowsePrint.Enabled := not IsEmpty;
finally
Screen.Cursor := crDefault;
end;
end;
procedure TfrmBrowseInvoicePrint.FormShow(Sender: TObject);
var
Ayear, Amonth, Aday: Word;
begin
inherited;
edtPaydate.Date := Date;
edtCustID.SetFocus;
edtInvoice.Text := FopCurrInvoice;
edtInvoice.Properties.MaxLength := FopInvoiceLength;
// 显示广东省商品统一发票相关字段信息
{$IFDEF DJSR}
DecodeDate(Date, Ayear, Amonth, Aday);
spinYear.Value := Ayear;
spinMonth.Value := Amonth;
spinDay.Value := Aday;
edtCharge.EditValue := GUserID;
edtCollector.EditValue := FopCollector;
edtCompany.Text := FopCompany;
edtInvoiceNO.Text := FopCurrInvoice;
edtInvoiceNO.Properties.MaxLength := FopInvoiceLength;
edtCustomer.SetFocus;
{$ENDIF DJSR}
end;
procedure TfrmBrowseInvoicePrint.edtCustIDKeyPress(Sender: TObject;
var Key: Char);
begin
inherited;
if Key = #13 then
edtCustIDExit(Sender);
end;
procedure TfrmBrowseInvoicePrint.actBrowsePrintExecute(Sender: TObject);
// 打印发票
const
ReportTitle = '广东省商品销售统一发票';
var
ARepfile, Astr: string;
APrintCount: Integer;
procedure ResetMtabPrint;
// 打开内存表,并清空
begin
with dmInvPrint.mtabPrint do
begin
Close;
Open;
Last;
while not Bof do
begin
Delete; Prior;
end;
end;
end;
function PrintRecord: Boolean;
// 打印一笔用水记录
var
ARepared: Boolean;
AID: Integer;
Ayear, Amonth, Aday: Word;
APayment: Double;
APaydate: TDateTime;
AInvoice: string;
begin
ResetMtabPrint;
ARepared := PrepareData; // 准备数据
if not ARepared then
begin
Result := ARepared;
Exit;
end;
with dmInvPrint, dmInvPrint.AqryPrint do
begin
AID := FieldByName('WRID').AsInteger;
APayment := FieldByName('Amont').AsFloat;
// 此处没有考虑多用户并发操作,严格的应该从全局文件中取出当前发票号码
{$IFDEF DJSR}
Ayear := spinYear.Value;
Amonth := spinMonth.Value;
Aday := spinDay.Value;
APaydate := EncodeDate(Ayear, Amonth, Aday);
AInvoice := edtInvoiceNO.Text;
{$ELSE}
APaydate := edtPaydate.Date;
AInvoice := edtInvoice.Text;
{$ENDIF DJSR}
if not ChargeWaterfee(AID, True, APayment, APaydate, FopCollector, AInvoice) then
begin
ShowMessage('保存打印信息失败,请稍后再试 。');
Result := False;
Exit;
end;
RMDataSet.DataSet := mtabPrint;
RMReport.Title := ReportTitle + Format(',发票号:%s', [{$IFDEF DJSR}edtInvoiceNO.Text{$ELSE}edtInvoice.Text{$ENDIF DJSR}]);
RMReport.PrepareReport;
// 只在第一次打印时允许用户进行格式设置
if APrintCount > 1 then
RMReport.PrintPreparedReportDlg
else
if FopPreview then // 预览
RMReport.ShowReport
else
if FopShowDialog then // 显示打印对话框
RMReport.PrintReport
else
RMReport.PrintPreparedReportDlg; // 直接打印
// 更新发票号码,此处没有考虑多用户并发操作
if not chkStopUpdateInvoice.Checked then
{$IFDEF DJSR}
edtInvoiceNO.Text := PrefixStr('0', IntToStr(StrToInt(edtInvoiceNO.Text) + 1), FopInvoiceLength);
{$ELSE}
edtInvoice.Text := PrefixStr('0', IntToStr(StrToInt(edtInvoice.Text) + 1), FopInvoiceLength);
{$ENDIF}
end;
Result := True;
end;
procedure RefreshTable;
begin
with dmInvPrint.AqryPrint do
try
Close;
Open;
except
ShowMessage('刷新当前已经打印的资料时失败 。');
end;
end;
function IsSeriesPrint: Boolean;
// 检查是否需要连续打印所有发票
begin
Result := {$IFDEF DJSR}chkSeriesPrint1.Checked {$ELSE} chkSeriesPrint.Checked{$ENDIF DJSR};
end;
function CheckInvoice: Boolean;
// 检查发票号码是否已经用完
begin
{$IFDEF DJSR}
Result := (StrToInt(edtInvoiceNO.Text) >= StrToInt(FopStartInv)) and (StrToInt(edtInvoiceNO.Text) <= StrToInt(FopEndInv));
{$ELSE}
Result := (StrToInt(edtInvoice.Text) >= StrToInt(FopStartInv)) and (StrToInt(edtInvoice.Text) <= StrToInt(FopEndInv));
{$ENDIF DJSR}
end;
begin
//inherited;
LoadSetting; // 加载打印选项
ARepfile := ExtractFilePath(Application.ExeName) + 'Report\' + ReportTitle + '.rmf';
if not FileExists(ARepfile) then
begin
ShowMessage(Format('发票格式文件 “%s” 丢失,请与系统开发商联系 。', [ReportTitle]));
Exit;
end;
try
{$IFDEF DJSR}
StrToInt(edtInvoiceNO.Text);
{$ELSE}
StrToInt(edtInvoice.Text);
{$ENDIF DJSR}
except
ShowMessage('你没有输入正确的发票号码,请确认后再试 。');
{$IFDEF DJSR}
edtInvoiceNO.SetFocus;
{$ELSE}
edtInvoice.SetFocus;
{$ENDIF DJSR}
Exit;
end;
if not CheckInvoice then
begin
ShowMessage('您领用的发票已经使用完,请重新设置开始和结束号码 。');
Exit;
end;
// 询问用户是否打印发票
if IsSeriesPrint then
Astr := Format('当前一共有 %d 笔数据,请准备好发票。现在打印吗?', [dmInvPrint.AqryPrint.RecordCount])
else
Astr := '请准备好发票,现在就打印这笔数据吗?';
if Application.MessageBox(Pchar(Astr), Pchar('提示'), MB_YESNO) = IDNO then
Exit;
if grdBrowse.DataSource.DataSet.IsEmpty then
begin
ShowMessage('当前没有待打印的发票资料 。');
Exit;
end;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -