2008-08-06 18:18:27 +00:00
|
|
|
|
unit uRptWordCertificadoTrabajo_Server;
|
|
|
|
|
|
|
|
|
|
|
|
interface
|
|
|
|
|
|
|
|
|
|
|
|
uses
|
|
|
|
|
|
SysUtils, Classes, AHWord97, IB, IBCustomDataSet, IBDatabase,
|
|
|
|
|
|
Word2000,
|
|
|
|
|
|
uDAInterfaces, uDADataStreamer, uDABin2DataStreamer, uDAClasses,
|
|
|
|
|
|
uDAScriptingProvider, uDADataTable, uDAMemDataTable;
|
|
|
|
|
|
|
|
|
|
|
|
type
|
|
|
|
|
|
TCapitulo = record
|
|
|
|
|
|
Tipo : string;
|
|
|
|
|
|
Nombre : string;
|
|
|
|
|
|
Total : double;
|
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
|
|
TRptWordCertificadoTrabajo = class(TDataModule)
|
|
|
|
|
|
DABin2DataStreamer: TDABin2DataStreamer;
|
|
|
|
|
|
tbl_Cabecera: TDAMemDataTable;
|
|
|
|
|
|
tbl_Capitulos: TDAMemDataTable;
|
|
|
|
|
|
tbl_Empresa: TDAMemDataTable;
|
|
|
|
|
|
schReport: TDASchema;
|
|
|
|
|
|
DataDictionary: TDADataDictionary;
|
|
|
|
|
|
procedure DataModuleCreate(Sender: TObject);
|
|
|
|
|
|
private
|
|
|
|
|
|
FConnection: IDAConnection;
|
|
|
|
|
|
FImportes : Boolean;
|
2009-07-09 08:24:19 +00:00
|
|
|
|
// FDesBonificacion : Variant;
|
|
|
|
|
|
// FImpBonificacion : Double;
|
2008-08-06 18:18:27 +00:00
|
|
|
|
FPlantilla : string;
|
|
|
|
|
|
FWordApp : TWordApp;
|
|
|
|
|
|
FDocumento : TWordDoc;
|
|
|
|
|
|
FNumCapitulos : Integer;
|
|
|
|
|
|
FNumCapOpc : Integer;
|
|
|
|
|
|
FContadorCap : Integer;
|
|
|
|
|
|
FCodigoPresupuesto : Integer;
|
|
|
|
|
|
FNombreFichero : String;
|
|
|
|
|
|
ListaCapitulos : array[1..1000] of TCapitulo;
|
|
|
|
|
|
function Generar : Boolean;
|
|
|
|
|
|
function RellenarInforme : boolean; virtual;
|
|
|
|
|
|
procedure _GenerarCertificado(const AID : Integer);
|
|
|
|
|
|
public
|
|
|
|
|
|
constructor Create (AOwner : TComponent); override;
|
|
|
|
|
|
destructor Destroy; override;
|
|
|
|
|
|
function Exportar(const AIDPresupuesto: Integer; const AFichero : String): Boolean;
|
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
implementation
|
|
|
|
|
|
|
|
|
|
|
|
{$R *.dfm}
|
|
|
|
|
|
|
|
|
|
|
|
uses
|
|
|
|
|
|
Windows, Variants, Dialogs, uDataModuleServer, uStringsUtils, uSistemaFunc,
|
|
|
|
|
|
srvEmpresas_Impl, uROTypes, uROClasses;
|
|
|
|
|
|
|
|
|
|
|
|
const
|
|
|
|
|
|
rptInforme = 'CertificadoTrabajos.rdx';
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
constructor TRptWordCertificadoTrabajo.Create(AOwner: TComponent);
|
|
|
|
|
|
begin
|
|
|
|
|
|
inherited;
|
|
|
|
|
|
FDocumento := NIL;
|
|
|
|
|
|
FImportes := True;
|
|
|
|
|
|
FNumCapitulos := 0;
|
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
|
|
procedure TRptWordCertificadoTrabajo.DataModuleCreate(Sender: TObject);
|
|
|
|
|
|
begin
|
|
|
|
|
|
schReport.ConnectionManager := dmServer.ConnectionManager;
|
|
|
|
|
|
FConnection := dmServer.DarNuevaConexion;
|
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
|
|
destructor TRptWordCertificadoTrabajo.Destroy;
|
|
|
|
|
|
begin
|
|
|
|
|
|
if FDocumento <> NIL then
|
|
|
|
|
|
FDocumento.Free;
|
|
|
|
|
|
FDocumento := NIL;
|
|
|
|
|
|
|
|
|
|
|
|
inherited;
|
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
|
|
function TRptWordCertificadoTrabajo.Exportar(const AIDPresupuesto: Integer;
|
|
|
|
|
|
const AFichero : String): Boolean;
|
|
|
|
|
|
begin
|
|
|
|
|
|
if EsCadenaVacia(AFichero) then
|
|
|
|
|
|
RaiseError('Falta indicar el fichero donde se exportar<61> el listado.');
|
|
|
|
|
|
|
|
|
|
|
|
FNombreFichero := AFichero;
|
|
|
|
|
|
FCodigoPresupuesto := AIDPresupuesto;
|
|
|
|
|
|
_GenerarCertificado(AIDPresupuesto);
|
|
|
|
|
|
Result := True;
|
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
|
|
function TRptWordCertificadoTrabajo.Generar : Boolean;
|
|
|
|
|
|
begin
|
|
|
|
|
|
FWordApp := TWordApp.Create (False, False);
|
|
|
|
|
|
with FWordApp do
|
|
|
|
|
|
begin
|
|
|
|
|
|
Visible := False;
|
|
|
|
|
|
ScreenUpdating := False;
|
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
|
|
FDocumento := TWordDoc.CreateNewDoc(FWordApp, FPlantilla);
|
2008-09-10 16:49:09 +00:00
|
|
|
|
FWordApp.SaveActiveDocAs(FNombreFichero);
|
2008-08-06 18:18:27 +00:00
|
|
|
|
try
|
|
|
|
|
|
if not RellenarInforme then
|
|
|
|
|
|
RaiseError('Se producido un error al generar el informe en MS Word.');
|
|
|
|
|
|
|
2008-09-10 16:49:09 +00:00
|
|
|
|
FWordApp.CloseApp(wdSaveChanges);
|
2008-08-06 18:18:27 +00:00
|
|
|
|
Result := True;
|
|
|
|
|
|
finally
|
|
|
|
|
|
FDocumento := NIL;
|
|
|
|
|
|
FWordApp := NIL;
|
|
|
|
|
|
end;
|
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function TRptWordCertificadoTrabajo.RellenarInforme: boolean;
|
|
|
|
|
|
var
|
2008-08-08 12:08:18 +00:00
|
|
|
|
NombreCapitulo : string;
|
|
|
|
|
|
ADescripcion : string;
|
|
|
|
|
|
ANombreFichero : string;
|
2008-08-06 18:18:27 +00:00
|
|
|
|
begin
|
|
|
|
|
|
with FDocumento, tbl_Cabecera do
|
|
|
|
|
|
begin
|
|
|
|
|
|
ReplaceBookmark('Cliente', FieldByName('NOMBRE').AsString);
|
2020-06-17 15:41:54 +00:00
|
|
|
|
ReplaceBookmark('Direccion', '');
|
|
|
|
|
|
|
|
|
|
|
|
//Solictado por Maribel direcci<63>n Vacia.
|
|
|
|
|
|
{ ReplaceBookmark('Direccion', FieldByName('CALLE').AsString + ' ' +
|
2008-08-06 18:18:27 +00:00
|
|
|
|
FieldByName('CODIGO_POSTAL').AsString + ' ' +
|
|
|
|
|
|
FieldByName('POBLACION').AsString + ' ' + FieldByName('PROVINCIA').AsString);
|
2020-06-17 15:41:54 +00:00
|
|
|
|
}
|
2008-08-06 18:18:27 +00:00
|
|
|
|
|
2008-08-08 12:08:18 +00:00
|
|
|
|
ReplaceBookmark('Referencia', FieldByName('REFERENCIA').AsString);
|
2008-08-06 18:18:27 +00:00
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
|
|
FContadorCap := 0;
|
|
|
|
|
|
FNumCapOpc := 0;
|
|
|
|
|
|
with FDocumento, tbl_Capitulos do
|
|
|
|
|
|
begin
|
|
|
|
|
|
First;
|
2008-08-08 12:08:18 +00:00
|
|
|
|
ADescripcion := '';
|
2008-08-06 18:18:27 +00:00
|
|
|
|
while not Eof do
|
|
|
|
|
|
begin
|
|
|
|
|
|
if (FieldByName('TIPO_DETALLE').AsString = 'Titulo') or
|
|
|
|
|
|
(FieldByName('TIPO_DETALLE').AsString = 'Opcional') then
|
|
|
|
|
|
begin
|
|
|
|
|
|
NombreCapitulo := '';
|
|
|
|
|
|
if (FieldByName('TIPO_DETALLE').AsString = 'Titulo') then
|
|
|
|
|
|
NombreCapitulo := 'Cap<61>tulo ' + IntToStr(FContadorCap + 1) + '. ' + FieldByName('CONCEPTO').AsString
|
|
|
|
|
|
else begin
|
|
|
|
|
|
NombreCapitulo := 'Cap<61>tulo opcional. ' + FieldByName('CONCEPTO').AsString;
|
|
|
|
|
|
Inc(FNumCapOpc);
|
|
|
|
|
|
end;
|
|
|
|
|
|
ADescripcion := ADescripcion + #13#10 + NombreCapitulo;
|
|
|
|
|
|
|
|
|
|
|
|
Inc(FContadorCap);
|
|
|
|
|
|
ListaCapitulos[FContadorCap].Tipo := FieldByName('TIPO_DETALLE').AsString;
|
|
|
|
|
|
ListaCapitulos[FContadorCap].Nombre := NombreCapitulo;
|
|
|
|
|
|
Next;
|
|
|
|
|
|
end
|
|
|
|
|
|
else begin
|
|
|
|
|
|
if FContadorCap = 0 then
|
|
|
|
|
|
begin
|
|
|
|
|
|
Inc(FContadorCap); // Se considera el conjunto de conceptos sueltos como un cap<61>tulo.
|
|
|
|
|
|
{ Pegar una tabla para rellenarla }
|
|
|
|
|
|
end;
|
|
|
|
|
|
Next;
|
|
|
|
|
|
end;
|
|
|
|
|
|
end;
|
|
|
|
|
|
FNumCapitulos := FContadorCap;
|
2008-08-08 12:08:18 +00:00
|
|
|
|
ReplaceBookmark('Capitulos', ADescripcion);
|
2008-08-06 18:18:27 +00:00
|
|
|
|
end;
|
2008-08-08 12:08:18 +00:00
|
|
|
|
|
|
|
|
|
|
ANombreFichero := DarFicheroTemporal;
|
|
|
|
|
|
EscribirEnFichero(ANombreFichero, tbl_Cabecera.FieldByName('PORTADA').AsString);
|
|
|
|
|
|
FWordApp.InsertFile(ANombreFichero, 'Portada');
|
|
|
|
|
|
SysUtils.DeleteFile(ANombreFichero);
|
|
|
|
|
|
|
2008-08-06 18:18:27 +00:00
|
|
|
|
Result := True;
|
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
procedure TRptWordCertificadoTrabajo._GenerarCertificado(const AID: Integer);
|
|
|
|
|
|
var
|
|
|
|
|
|
ACopiaPlantilla: string;
|
|
|
|
|
|
begin
|
2008-10-31 18:16:49 +00:00
|
|
|
|
FConnection.BeginTransaction; //<--- Creo que no va a hacer falta. "PUES SI ES NECESARIO"
|
|
|
|
|
|
try
|
|
|
|
|
|
tbl_Cabecera.ParamByName('ID').AsInteger := AID;
|
|
|
|
|
|
tbl_Capitulos.ParamByName('ID_PRESUPUESTO').AsInteger := AID;
|
2008-08-06 18:18:27 +00:00
|
|
|
|
|
2008-10-31 18:16:49 +00:00
|
|
|
|
tbl_Cabecera.Active := True;
|
|
|
|
|
|
tbl_Capitulos.Active := True;
|
2008-08-06 18:18:27 +00:00
|
|
|
|
|
2015-10-26 18:33:00 +00:00
|
|
|
|
FPlantilla := DarRutaInformes + tbl_Cabecera.FieldByName('ID_EMPRESA').AsString + '\' + rptInforme;
|
2008-10-31 18:16:49 +00:00
|
|
|
|
FCodigoPresupuesto := AID;
|
2008-08-06 18:18:27 +00:00
|
|
|
|
|
2008-10-31 18:16:49 +00:00
|
|
|
|
if RecuperarEmpresa(tbl_Cabecera.FieldByName('ID_EMPRESA').AsInteger, tbl_Empresa) then
|
|
|
|
|
|
begin
|
|
|
|
|
|
ACopiaPlantilla := DarFicheroTemporal;
|
|
|
|
|
|
CopiarFichero(FPlantilla, ACopiaPlantilla);
|
|
|
|
|
|
FPlantilla := ACopiaPlantilla;
|
|
|
|
|
|
try
|
|
|
|
|
|
Generar;
|
|
|
|
|
|
finally
|
|
|
|
|
|
SysUtils.DeleteFile(ACopiaPlantilla);
|
|
|
|
|
|
end;
|
2008-08-06 18:18:27 +00:00
|
|
|
|
end;
|
2008-10-31 18:16:49 +00:00
|
|
|
|
finally
|
|
|
|
|
|
FConnection.RollbackTransaction; //<--- Creo que no va a hacer falta. "PUES SI ES NECESARIO"
|
2008-08-06 18:18:27 +00:00
|
|
|
|
end;
|
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
|
|
end.
|
|
|
|
|
|
|