Tecsitel_FactuGES2/Source/Modulos/Gestor de informes/Views/uViewPeriodoFechas.pas

388 lines
11 KiB
ObjectPascal

unit uViewPeriodoFechas;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, cxGraphics, cxEdit, cxDropDownEdit, cxCalendar, StdCtrls,
cxControls, cxContainer, cxTextEdit, cxMaskEdit, TBXDkPanels,
cxEditRepositoryItems, dxLayoutControl, dxLayoutLookAndFeels, uViewBase,
Mask, JvExMask, JvToolEdit, TB2Dock, uViewParametrosInforme;
type
IViewPeriodoFechas = interface(IViewParametrosInforme)
['{793084E2-873E-4C57-8BD6-9087816CCF3A}']
end;
TTipoFecha = (TFecha, TFechaVencimiento);
TfrViewPeriodoFechas = class(TfrViewParametrosInforme, IViewPeriodoFechas)
cxRepository: TcxEditRepository;
cxRepositoryPeriodos: TcxEditRepositoryComboBoxItem;
edtFechaIni: TcxDateEdit;
edtFechaFin: TcxDateEdit;
TBXLabel2: TTBXLabel;
TBXAlignmentPanel2: TTBXAlignmentPanel;
Label1: TLabel;
Label2: TLabel;
Label3: TLabel;
TBXAlignmentPanel3: TTBXAlignmentPanel;
Label4: TLabel;
Label5: TLabel;
Label6: TLabel;
edtFechaVenFin: TcxDateEdit;
edtFechaVenIni: TcxDateEdit;
cbPeriodo: TcxComboBox;
cbPeriodo2: TcxComboBox;
procedure cbPeriodoPropertiesChange(Sender: TObject);
procedure edtFechaIni2PropertiesValidate(Sender: TObject;
var DisplayValue: Variant; var ErrorText: TCaption;
var Error: Boolean);
procedure edtFechaFinPropertiesValidate(Sender: TObject;
var DisplayValue: Variant; var ErrorText: TCaption;
var Error: Boolean);
procedure cbPeriodo2PropertiesChange(Sender: TObject);
procedure edtFechaVenIniPropertiesValidate(Sender: TObject;
var DisplayValue: Variant; var ErrorText: TCaption; var Error: Boolean);
procedure edtFechaVenFinPropertiesValidate(Sender: TObject;
var DisplayValue: Variant; var ErrorText: TCaption; var Error: Boolean);
private
function GetFechaFinal: Variant;
function GetFechaInicial: Variant;
procedure SetFechaFinal(const Value: Variant);
procedure SetFechaInicial(const Value: Variant);
function GetFechaVenFinal: Variant;
function GetFechaVenInicial: Variant;
procedure SetFechaVenFinal(const Value: Variant);
procedure SetFechaVenInicial(const Value: Variant);
public
procedure Hoy(const ATipoFecha: TTipoFecha);
procedure Ayer(const ATipoFecha: TTipoFecha);
procedure EstaSemana(const ATipoFecha: TTipoFecha);
procedure EsteMes(const ATipoFecha: TTipoFecha);
procedure EsteAno(const ATipoFecha: TTipoFecha);
procedure Ultimos7dias(const ATipoFecha: TTipoFecha);
procedure Ultimos30dias(const ATipoFecha: TTipoFecha);
procedure Ultimos3meses(const ATipoFecha: TTipoFecha);
procedure MesAnterior(const ATipoFecha: TTipoFecha);
procedure AnoAnterior(const ATipoFecha: TTipoFecha);
procedure Personalizado(const ATipoFecha: TTipoFecha);
property FechaInicial : Variant read GetFechaInicial write SetFechaInicial;
property FechaFinal : Variant read GetFechaFinal write SetFechaFinal;
property FechaVenInicial : Variant read GetFechaVenInicial write SetFechaVenInicial;
property FechaVenFinal : Variant read GetFechaVenFinal write SetFechaVenFinal;
constructor Create(AOwner: TComponent); override;
end;
implementation
uses DateUtils;
{$R *.dfm}
procedure TfrViewPeriodoFechas.AnoAnterior(const ATipoFecha: TTipoFecha);
begin
case ATipoFecha of
TFecha: begin
edtFechaIni.Date := StartOfTheYear(IncYear(Today, -1));
edtFechaFin.Date := EndOfTheYear(IncYear(Today, -1));
end;
TFechaVencimiento: begin
edtFechaVenIni.Date := StartOfTheYear(IncYear(Today, -1));
edtFechaVenFin.Date := EndOfTheYear(IncYear(Today, -1));
end;
end;
end;
procedure TfrViewPeriodoFechas.Ayer(const ATipoFecha: TTipoFecha);
begin
case ATipoFecha of
TFecha: begin
edtFechaIni.Date := Yesterday;
edtFechaFin.Date := Yesterday;
end;
TFechaVencimiento: begin
edtFechaVenIni.Date := Yesterday;
edtFechaVenFin.Date := Yesterday;
end;
end;
end;
procedure TfrViewPeriodoFechas.EstaSemana(const ATipoFecha: TTipoFecha);
begin
case ATipoFecha of
TFecha: begin
edtFechaIni.Date := StartOfTheWeek(Today);
edtFechaFin.Date := EndOfTheWeek(Today);
end;
TFechaVencimiento: begin
edtFechaVenIni.Date := StartOfTheWeek(Today);
edtFechaVenFin.Date := EndOfTheWeek(Today);
end;
end;
end;
procedure TfrViewPeriodoFechas.EsteAno(const ATipoFecha: TTipoFecha);
begin
case ATipoFecha of
TFecha: begin
edtFechaIni.Date := StartOfTheYear(Today);
edtFechaFin.Date := EndOfTheYear(Today);
end;
TFechaVencimiento: begin
edtFechaVenIni.Date := StartOfTheYear(Today);
edtFechaVenFin.Date := EndOfTheYear(Today);
end;
end;
end;
procedure TfrViewPeriodoFechas.EsteMes(const ATipoFecha: TTipoFecha);
begin
case ATipoFecha of
TFecha: begin
edtFechaIni.Date := StartOfTheMonth(Today);
edtFechaFin.Date := EndOfTheMonth(Today);
end;
TFechaVencimiento: begin
edtFechaVenIni.Date := StartOfTheMonth(Today);
edtFechaVenFin.Date := EndOfTheMonth(Today);
end;
end;
end;
function TfrViewPeriodoFechas.GetFechaFinal: Variant;
begin
Result := edtFechaFin.EditValue;
end;
function TfrViewPeriodoFechas.GetFechaInicial: Variant;
begin
Result := edtFechaIni.EditValue;
end;
function TfrViewPeriodoFechas.GetFechaVenFinal: Variant;
begin
Result := edtFechaVenFin.EditValue;
end;
function TfrViewPeriodoFechas.GetFechaVenInicial: Variant;
begin
Result := edtFechaVenIni.EditValue;
end;
procedure TfrViewPeriodoFechas.Hoy(const ATipoFecha: TTipoFecha);
begin
case ATipoFecha of
TFecha: begin
edtFechaIni.Date := Today;
edtFechaFin.Date := Today;
end;
TFechaVencimiento: begin
edtFechaVenIni.Date := Today;
edtFechaVenFin.Date := Today;
end;
end;
end;
procedure TfrViewPeriodoFechas.MesAnterior(const ATipoFecha: TTipoFecha);
begin
case ATipoFecha of
TFecha: begin
edtFechaIni.Date := StartOfTheMonth(IncMonth(Today, -1));
edtFechaFin.Date := EndOfTheMonth(IncMonth(Today, -1));
end;
TFechaVencimiento: begin
edtFechaVenIni.Date := StartOfTheMonth(IncMonth(Today, -1));
edtFechaVenFin.Date := EndOfTheMonth(IncMonth(Today, -1));
end;
end;
end;
procedure TfrViewPeriodoFechas.Personalizado(const ATipoFecha: TTipoFecha);
begin
case ATipoFecha of
TFecha: begin
edtFechaIni.SetFocus;
end;
TFechaVencimiento: begin
edtFechaVenIni.SetFocus;
end;
end;
end;
procedure TfrViewPeriodoFechas.SetFechaFinal(const Value: Variant);
begin
edtFechaFin.EditValue := Value;
end;
procedure TfrViewPeriodoFechas.SetFechaInicial(const Value: Variant);
begin
edtFechaIni.EditValue := Value;
end;
procedure TfrViewPeriodoFechas.SetFechaVenFinal(const Value: Variant);
begin
edtFechaVenFin.EditValue := Value;
end;
procedure TfrViewPeriodoFechas.SetFechaVenInicial(const Value: Variant);
begin
edtFechaVenIni.EditValue := Value;
end;
procedure TfrViewPeriodoFechas.Ultimos30dias(const ATipoFecha: TTipoFecha);
begin
case ATipoFecha of
TFecha: begin
edtFechaIni.Date := IncDay(Today, -30);
edtFechaFin.Date := Today
end;
TFechaVencimiento: begin
edtFechaVenIni.Date := IncDay(Today, -30);
edtFechaVenFin.Date := Today
end;
end;
end;
procedure TfrViewPeriodoFechas.Ultimos3meses(const ATipoFecha: TTipoFecha);
begin
case ATipoFecha of
TFecha: begin
edtFechaIni.Date := IncMonth(Today, -3);
edtFechaFin.Date := Today
end;
TFechaVencimiento: begin
edtFechaVenIni.Date := IncMonth(Today, -3);
edtFechaVenFin.Date := Today
end;
end;
end;
procedure TfrViewPeriodoFechas.Ultimos7dias(const ATipoFecha: TTipoFecha);
begin
case ATipoFecha of
TFecha: begin
edtFechaIni.Date := IncDay(Today, -7);
edtFechaFin.Date := Today
end;
TFechaVencimiento: begin
edtFechaVenIni.Date := IncDay(Today, -7);
edtFechaVenFin.Date := Today
end;
end;
end;
procedure TfrViewPeriodoFechas.cbPeriodo2PropertiesChange(Sender: TObject);
begin
case (Sender as TcxComboBox).ItemIndex of
0 : Hoy(TFechaVencimiento);
1 : Ayer(TFechaVencimiento);
2 : EstaSemana(TFechaVencimiento);
3 : EsteMes(TFechaVencimiento);
4 : EsteAno(TFechaVencimiento);
5 : Ultimos7dias(TFechaVencimiento);
6 : Ultimos30dias(TFechaVencimiento);
7 : Ultimos3meses(TFechaVencimiento);
8 : MesAnterior(TFechaVencimiento);
9 : AnoAnterior(TFechaVencimiento);
else
Personalizado(TFechaVencimiento);
end;
end;
procedure TfrViewPeriodoFechas.cbPeriodoPropertiesChange(Sender: TObject);
begin
case (Sender as TcxComboBox).ItemIndex of
0 : Hoy(TFecha);
1 : Ayer(TFecha);
2 : EstaSemana(TFecha);
3 : EsteMes(TFecha);
4 : EsteAno(TFecha);
5 : Ultimos7dias(TFecha);
6 : Ultimos30dias(TFecha);
7 : Ultimos3meses(TFecha);
8 : MesAnterior(TFecha);
9 : AnoAnterior(TFecha);
else
Personalizado(TFecha);
end;
end;
constructor TfrViewPeriodoFechas.Create(AOwner: TComponent);
begin
inherited;
cbPeriodo.ItemIndex := -1;
cbPeriodo2.ItemIndex := -1;
// EsteMes(TFecha);
end;
procedure TfrViewPeriodoFechas.edtFechaIni2PropertiesValidate(
Sender: TObject; var DisplayValue: Variant; var ErrorText: TCaption;
var Error: Boolean);
begin
inherited;
if Length(VarToStr(DisplayValue)) > 0 then
begin
if DisplayValue <> edtFechaIni.Date then
cbPeriodo.ItemIndex := 12;
if DisplayValue > edtFechaFin.Date then
begin
edtFechaFin.EditText := DisplayValue;
edtFechaFin.ValidateEdit(True);
end;
end;
end;
procedure TfrViewPeriodoFechas.edtFechaVenFinPropertiesValidate(Sender: TObject;
var DisplayValue: Variant; var ErrorText: TCaption; var Error: Boolean);
begin
if Length(VarToStr(DisplayValue)) > 0 then
begin
if DisplayValue <> edtFechaVenFin.Date then
cbPeriodo2.ItemIndex := 12;
if DisplayValue < edtFechaVenIni.Date then
begin
edtFechaVenIni.EditText := DisplayValue;
edtFechaVenIni.ValidateEdit(True);
end;
end;
end;
procedure TfrViewPeriodoFechas.edtFechaVenIniPropertiesValidate(Sender: TObject;
var DisplayValue: Variant; var ErrorText: TCaption; var Error: Boolean);
begin
inherited;
if Length(VarToStr(DisplayValue)) > 0 then
begin
if DisplayValue <> edtFechaVenIni.Date then
cbPeriodo2.ItemIndex := 12;
if DisplayValue > edtFechaVenFin.Date then
begin
edtFechaVenFin.EditText := DisplayValue;
edtFechaVenFin.ValidateEdit(True);
end;
end;
end;
procedure TfrViewPeriodoFechas.edtFechaFinPropertiesValidate(
Sender: TObject; var DisplayValue: Variant; var ErrorText: TCaption;
var Error: Boolean);
begin
inherited;
if Length(VarToStr(DisplayValue)) > 0 then
begin
if DisplayValue <> edtFechaFin.Date then
cbPeriodo.ItemIndex := 12;
if DisplayValue < edtFechaIni.Date then
begin
edtFechaIni.EditText := DisplayValue;
edtFechaIni.ValidateEdit(True);
end;
end;
end;
end.