This repository has been archived on 2024-11-29. You can view files and clone it, but cannot push or open issues or pull requests.
Tecsitel_FactuGES/Cartas/EditorCartas.pas
2007-06-21 15:47:20 +00:00

423 lines
14 KiB
ObjectPascal

{
===============================================================================
Copyright (©) 2001. Rodax Software.
===============================================================================
Los contenidos de este fichero son propiedad de Rodax Software titular del
copyright. Este fichero sólo podrá ser copiado, distribuido y utilizado,
en su totalidad o en parte, con el permiso escrito de Rodax Software, o de
acuerdo con los términos y condiciones establecidas en el acuerdo/contrato
bajo el que se suministra.
-----------------------------------------------------------------------------
Web: www.rodax-software.com
===============================================================================
Fecha primera versión: 01-10-2001
Versión actual: 1.0.4
Fecha versión actual: 18-03-2005
===============================================================================
Modificaciones:
Fecha Comentarios
---------------------------------------------------------------------------
15-10-2001 Se ha cambiado la fuente del rich-edit de Tahoma a Garamond
para que coincida con la fuente que se usa en la plantilla
de Word.
22-03-2003 Se han puesto componentes con calendario.
26-04-2004 Se rellena atomáticamente la fecha de emisión.
18-03-2005 Poder enviar las cartas firmadas o no, por correo electrónico
===============================================================================
}
unit EditorCartas;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
RDXFRAME, StdCtrls, RdxComboBox, RdxBotones, RdxCampos,
ExtCtrls, Tipos, RdxBarras, RdxTitulos, Configuracion,
Grids, DBGrids, RdxPaneles, RdxRadioButton, RdxShape, RdxDialogos,
ComCtrls, RdxRichEdit, TablaProveedores, TablaClientes, dxCntner,
dxEditor, dxExEdtr, dxEdLib, cxControls, cxContainer, cxEdit, cxTextEdit,
cxMaskEdit, cxDropDownEdit, cxCalendar, cxButtonEdit;
type
TfrEditorCartas = class(TRdxFrame)
eInformacion: TLabel;
Panel: TRdxPanel;
pnlDatos: TRdxPanel;
cDatos: TRdxCabecera;
eCodigo: TLabel;
eNombre: TLabel;
ePersonaContacto: TLabel;
eCalle: TLabel;
ePiso: TLabel;
eNumero: TLabel;
eCodigoPostal: TLabel;
ePoblacion: TLabel;
eFecha: TLabel;
Carta: TRdxRichEdit;
Calle: TRdxEdit;
Poblacion: TRdxEdit;
Nombre: TRdxEdit;
Numero: TRdxEdit;
Piso: TRdxEdit;
CodigoPostal: TRdxEdit;
PersonaContacto: TRdxEdit;
brOperacion: TRdxBarraInferior;
bImprimir: TRdxBoton;
bCancelar: TRdxBoton;
bExportar: TRdxBoton;
eCarta: TLabel;
Fecha: TcxDateEdit;
CodigoProvCli: TcxButtonEdit;
bEnviar: TRdxBoton;
procedure bImprimirClick(Sender: TObject);
procedure bCancelarClick(Sender: TObject);
procedure bExportarClick(Sender: TObject);
procedure bEnviarClick(Sender: TObject);
procedure CodigoProvCliPropertiesButtonClick(Sender: TObject;
AButtonIndex: Integer);
procedure CodigoProvCliPropertiesValidate(Sender: TObject;
var DisplayValue: Variant; var ErrorText: TCaption;
var Error: Boolean);
private
DatosProveedor : TDatosProveedor;
DatosCliente : TDatosCliente;
function ComprobarDatos: boolean;
procedure rellenarCampos(DatosProveedor:TDatosProveedor); overload;
procedure rellenarCampos(DatosCliente:TDatosCliente); overload;
procedure ImprimirCarta;
procedure ExportarCarta;
protected
FCodigo : Variant;
procedure SetCodigo(Value : Variant);
function CambiarEntidad(EntidadAnterior, Entidad : TRdxEntidad): Boolean; override;
procedure FreeContenido; override;
public
property Codigo : Variant read FCodigo write SetCodigo;
constructor Create(AOwner : TComponent); override;
destructor Destroy; override;
end;
var
frEditorCartas: TfrEditorCartas;
implementation
{$R *.DFM}
uses
Proveedores, Clientes, Mensajes, StrFunc, InformeCarta, SysFunc, NumFunc,
RdxFrameArticulos, Almacenes, Colores, Literales, Correo, Constantes;
constructor TfrEditorCartas.Create(AOwner : TComponent);
begin
inherited Create(AOwner);
FCodigo := NULL;
DatosProveedor := TDatosProveedor.Create;
DatosCliente := TDatosCliente.Create;
Fecha.Date := Date;
end;
destructor TfrEditorCartas.Destroy;
begin
DatosProveedor.Free;
DatosCliente.Free;
inherited;
end;
procedure TfrEditorCartas.bCancelarClick(Sender: TObject);
begin
CloseFrame;
end;
procedure TfrEditorCartas.ExportarCarta;
var
FInformeCarta : TInformeCarta;
Fichero : String;
begin
if not DarFicheroExportar(Fichero) then
Exit;
FInformeCarta := TInformeCarta.Create(Self);
try
FInformeCarta.FNombre := Nombre.Text;
FInformeCarta.FDireccion := Format('%s, %s. %s',[Calle.Text,Numero.Text,Piso.Text]);
FInformeCarta.FPoblacion := Format('%s %s',[Poblacion.Text,CodigoPostal.Text]);
FInformeCarta.FPersonaContacto := PersonaContacto.Text;
FInformeCarta.FFecha := Fecha.Text;
FInformeCarta.FNombreFicheroCarta := DarFicheroTemporal;
Carta.Lines.SaveToFile(FInformeCarta.FNombreFicheroCarta);
FInformeCarta.Exportar(Fichero);
DeleteFile(FInformeCarta.FNombreFicheroCarta);
finally
FInformeCarta.Free;
end;
end;
procedure TfrEditorCartas.FreeContenido;
begin
if (ContenidoModal is TfrProveedores) then
Codigo := (ContenidoModal as TfrProveedores).CodigoProveedor;
if (ContenidoModal is TfrClientes) then
Codigo := (ContenidoModal as TfrClientes).CodigoCliente;
inherited FreeContenido;
end;
procedure TfrEditorCartas.SetCodigo(Value: Variant);
begin
if VarIsNull(Value) then
Exit;
FCodigo := Value;
case Entidad of
entProveedor: begin
DatosProveedor.Codigo := FCodigo;
if dmTablaProveedores.darDatosProveedor(DatosProveedor) then
rellenarCampos(DatosProveedor)
else
raise Exception.CreateFmt(msgProCodProvNoExiste, [FCodigo]);
end;
entCliente: begin
DatosCliente.Codigo := FCodigo;
if dmTablaClientes.darDatosCliente(DatosCliente) then
rellenarCampos(DatosCliente)
else
raise Exception.CreateFmt(msgProCodProvNoExiste, [FCodigo]);
end;
end;
end;
procedure TfrEditorCartas.bImprimirClick(Sender: TObject);
begin
if not ComprobarDatos then
Exit;
ImprimirCarta;
CloseFrame;
end;
procedure TfrEditorCartas.bExportarClick(Sender: TObject);
begin
if not ComprobarDatos then
Exit;
ExportarCarta;
CloseFrame;
end;
procedure TfrEditorCartas.ImprimirCarta;
var
FInformeCarta : TInformeCarta;
begin
FInformeCarta := TInformeCarta.Create(Self);
try
FInformeCarta.FNombre := Nombre.Text;
FInformeCarta.FDireccion := Format('%s, %s. %s',[Calle.Text,Numero.Text,Piso.Text]);
FInformeCarta.FPoblacion := Format('%s %s',[Poblacion.Text,CodigoPostal.Text]);
FInformeCarta.FPersonaContacto := PersonaContacto.Text;
FInformeCarta.FFecha := Fecha.Text;
FInformeCarta.FNombreFicheroCarta := DarFicheroTemporal;
Carta.Lines.SaveToFile(FInformeCarta.FNombreFicheroCarta);
FInformeCarta.Imprimir;
DeleteFile(FInformeCarta.FNombreFicheroCarta);
finally
FInformeCarta.Free;
end;
end;
function TfrEditorCartas.CambiarEntidad(EntidadAnterior,Entidad: TRdxEntidad): Boolean;
begin
inherited CambiarEntidad(EntidadAnterior, Entidad);
if Entidad = entCliente then
begin
cDatos.Caption := 'Datos del cliente';
eCodigo.Caption := 'Código de cliente';
end;
ConfigurarFrame(Self, Self.Entidad);
end;
procedure TfrEditorCartas.rellenarCampos(DatosProveedor: TDatosProveedor);
begin
CodigoProvCli.Text := DatosProveedor.Codigo;
Nombre.Text := DatosProveedor.Nombre;
Calle.Text := DatosProveedor.Calle;
Numero.Text := DatosProveedor.Numero;
Piso.Text := DatosProveedor.Piso;
Poblacion.Text := DatosProveedor.Poblacion;
CodigoPostal.Text := DatosProveedor.CodigoPostal;
PersonaContacto.Text := DatosProveedor.PersonaContacto;
end;
procedure TfrEditorCartas.rellenarCampos(DatosCliente: TDatosCliente);
begin
CodigoProvCli.Text := DatosCliente.Codigo;
Nombre.Text := DatosCliente.Nombre;
Calle.Text := DatosCliente.Calle;
Numero.Text := DatosCliente.Numero;
Piso.Text := DatosCliente.Piso;
Poblacion.Text := DatosCliente.Poblacion;
CodigoPostal.Text := DatosCliente.CodigoPostal;
PersonaContacto.Text := DatosCliente.PersonaContacto;
end;
function TfrEditorCartas.ComprobarDatos: boolean;
begin
Result := False;
if EsCadenaVacia(Nombre.Text) then
begin
Case Entidad of
entProveedor : VerMensaje(msgCarFaltaProv);
entCliente : VerMensaje(msgCarFaltaCli);
end;
Nombre.SetFocus;
Exit;
end;
if EsCadenaVacia(Calle.Text) then
begin
VerMensaje(msgCarFaltaDir);
Calle.SetFocus;
Exit;
end;
if EsCadenaVacia(Poblacion.Text) then
begin
VerMensaje(msgCarFaltaPob);
Poblacion.SetFocus;
Exit;
end;
if EsCadenaVacia(CodigoPostal.Text) then
begin
VerMensaje(msgCarFaltaCP);
CodigoPostal.SetFocus;
Exit;
end;
if EsCadenaVacia(Carta.Lines.Text) then
begin
VerMensaje(msgCarFaltaCarta);
Carta.SetFocus;
Exit;
end;
Result := True;
end;
procedure TfrEditorCartas.CodigoProvCliPropertiesButtonClick(
Sender: TObject; AButtonIndex: Integer);
begin
Case Entidad of
entProveedor: ContenidoModal := TfrProveedores.Create(Self);
entCliente : ContenidoModal := TfrClientes.Create(Self);
end;
end;
procedure TfrEditorCartas.CodigoProvCliPropertiesValidate(Sender: TObject;
var DisplayValue: Variant; var ErrorText: TCaption; var Error: Boolean);
begin
if EsCadenaVacia (DisplayValue) then
Exit;
Case Entidad of
entProveedor: begin
if (dmTablaProveedores.validarCodigo(DisplayValue)) then begin
//Comprueba que le numero es lo sufucientemente pequeño para ser un entero
if not EsInteger(DisplayValue) then
begin
VerMensajeFmt(msgProCodProvIncorrecto,[DisplayValue]);
DisplayValue := '0';
CodigoProvCli.SetFocus;
end
else
begin
DisplayValue := dmTablaProveedores.formatearCodigo(DisplayValue);
if (not dmTablaProveedores.existeCodigo(DisplayValue)) then begin
VerMensajeFmt(msgProCodProvNoExiste, [DisplayValue]);
CodigoProvCli.SetFocus;
Exit;
end;
Codigo := CodigoProvCli.Text;
end
end
else begin
VerMensajeFmt(msgProCodProvIncorrecto, [DisplayValue]);
CodigoProvCli.SetFocus;
Exit;
end;
end;
entCliente: begin
if (dmTablaClientes.validarCodigo(CodigoProvCli.Text)) then begin
//Comprueba que le numero es lo sufucientemente pequeño para ser un entero
if not EsInteger(DisplayValue) then
begin
VerMensajeFmt(msgCliCodCliIncorrecto,[DisplayValue]);
DisplayValue := '0';
CodigoProvCli.SetFocus;
end
else
begin
DisplayValue:= dmTablaClientes.formatearCodigo(CodigoProvCli.Text);
if (not dmTablaClientes.existeCodigo(DisplayValue)) then begin
VerMensajeFmt(msgCliCodCliNoExiste, [DisplayValue]);
CodigoProvCli.SetFocus;
Exit;
end;
Codigo := DisplayValue;
end
end
else begin
VerMensajeFmt(msgCliCodCliIncorrecto, [DisplayValue]);
CodigoProvCli.SetFocus;
Exit;
end;
end;
end;
end;
procedure TfrEditorCartas.bEnviarClick(Sender: TObject);
var
Datos: TDatosCorreo;
Codigo, Fichero : String;
FInformeCarta : TInformeCarta;
begin
Codigo := CodigoProvCli.Text;
Datos:= Nil;
Fichero := Codigo;
Fichero := DarRutaTemporal + StringReplace(Fichero, CTE_SEPSERIADO, CTE_SEPSERIADO2, [rfReplaceAll, rfIgnoreCase]);
Fichero := Fichero + CTE_DOC;
FInformeCarta := TInformeCarta.Create(Self);
try
FInformeCarta.FNombre := Nombre.Text;
FInformeCarta.FDireccion := Format('%s, %s. %s',[Calle.Text,Numero.Text,Piso.Text]);
FInformeCarta.FPoblacion := Format('%s %s',[Poblacion.Text,CodigoPostal.Text]);
FInformeCarta.FPersonaContacto := PersonaContacto.Text;
FInformeCarta.FFecha := Fecha.Text;
FInformeCarta.FNombreFicheroCarta := DarFicheroTemporal;
Carta.Lines.SaveToFile(FInformeCarta.FNombreFicheroCarta);
FInformeCarta.Exportar(Fichero);
finally
FInformeCarta.Free;
end;
try
//Creamos el correo
Datos:= TDatosCorreo.Create;
if Entidad = entCliente then
Datos.Direcciones.add(dmTablaClientes.darCorreo(Codigo))
else
Datos.Direcciones.add(dmTablaProveedores.darCorreo(Codigo));
Datos.Adjuntos.Add(Fichero);
enviarCorreo(Datos);
finally
FreeAndNil(Datos);
end;
end;
end.