git-svn-id: https://192.168.0.254/svn/Proyectos.Tecsitel_FactuGES2/trunk@1166 0c75b7a4-871f-7646-8a2f-f78d34cc349f
221 lines
6.2 KiB
ObjectPascal
221 lines
6.2 KiB
ObjectPascal
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;
|
||
// FDesBonificacion : Variant;
|
||
// FImpBonificacion : Double;
|
||
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);
|
||
FWordApp.SaveActiveDocAs(FNombreFichero);
|
||
try
|
||
if not RellenarInforme then
|
||
RaiseError('Se producido un error al generar el informe en MS Word.');
|
||
|
||
FWordApp.CloseApp(wdSaveChanges);
|
||
Result := True;
|
||
finally
|
||
FDocumento := NIL;
|
||
FWordApp := NIL;
|
||
end;
|
||
end;
|
||
|
||
|
||
function TRptWordCertificadoTrabajo.RellenarInforme: boolean;
|
||
var
|
||
NombreCapitulo : string;
|
||
ADescripcion : string;
|
||
ANombreFichero : string;
|
||
begin
|
||
with FDocumento, tbl_Cabecera do
|
||
begin
|
||
ReplaceBookmark('Cliente', FieldByName('NOMBRE').AsString);
|
||
ReplaceBookmark('Direccion', '');
|
||
|
||
//Solictado por Maribel direcci<63>n Vacia.
|
||
{ ReplaceBookmark('Direccion', FieldByName('CALLE').AsString + ' ' +
|
||
FieldByName('CODIGO_POSTAL').AsString + ' ' +
|
||
FieldByName('POBLACION').AsString + ' ' + FieldByName('PROVINCIA').AsString);
|
||
}
|
||
|
||
ReplaceBookmark('Referencia', FieldByName('REFERENCIA').AsString);
|
||
end;
|
||
|
||
FContadorCap := 0;
|
||
FNumCapOpc := 0;
|
||
with FDocumento, tbl_Capitulos do
|
||
begin
|
||
First;
|
||
ADescripcion := '';
|
||
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;
|
||
ReplaceBookmark('Capitulos', ADescripcion);
|
||
end;
|
||
|
||
ANombreFichero := DarFicheroTemporal;
|
||
EscribirEnFichero(ANombreFichero, tbl_Cabecera.FieldByName('PORTADA').AsString);
|
||
FWordApp.InsertFile(ANombreFichero, 'Portada');
|
||
SysUtils.DeleteFile(ANombreFichero);
|
||
|
||
Result := True;
|
||
end;
|
||
|
||
|
||
procedure TRptWordCertificadoTrabajo._GenerarCertificado(const AID: Integer);
|
||
var
|
||
ACopiaPlantilla: string;
|
||
begin
|
||
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;
|
||
|
||
tbl_Cabecera.Active := True;
|
||
tbl_Capitulos.Active := True;
|
||
|
||
FPlantilla := DarRutaInformes + tbl_Cabecera.FieldByName('ID_EMPRESA').AsString + '\' + rptInforme;
|
||
FCodigoPresupuesto := AID;
|
||
|
||
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;
|
||
end;
|
||
finally
|
||
FConnection.RollbackTransaction; //<--- Creo que no va a hacer falta. "PUES SI ES NECESARIO"
|
||
end;
|
||
end;
|
||
|
||
end.
|
||
|