2008-02-07 22:07:23 +00:00
|
|
|
|
unit uRptWordFacturaCliente;
|
|
|
|
|
|
|
|
|
|
|
|
interface
|
|
|
|
|
|
|
|
|
|
|
|
uses
|
|
|
|
|
|
SysUtils, Classes, AHWord97, IB, IBCustomDataSet, IBDatabase,
|
|
|
|
|
|
Word2000,
|
|
|
|
|
|
uDAInterfaces, uDADataStreamer, uDABin2DataStreamer, uDAClasses,
|
|
|
|
|
|
uDAScriptingProvider, uDADataTable, uDAMemDataTable;
|
|
|
|
|
|
|
|
|
|
|
|
type
|
|
|
|
|
|
TRptWordFacturaCliente = class(TDataModule)
|
|
|
|
|
|
DABin2DataStreamer: TDABin2DataStreamer;
|
|
|
|
|
|
tbl_Cabecera: TDAMemDataTable;
|
|
|
|
|
|
tbl_Detalles: TDAMemDataTable;
|
|
|
|
|
|
tbl_Empresa: TDAMemDataTable;
|
2008-09-08 15:46:28 +00:00
|
|
|
|
tbl_Vencimientos: TDAMemDataTable;
|
2008-02-07 22:07:23 +00:00
|
|
|
|
schReport: TDASchema;
|
|
|
|
|
|
DataDictionary: TDADataDictionary;
|
|
|
|
|
|
procedure DataModuleCreate(Sender: TObject);
|
|
|
|
|
|
private
|
|
|
|
|
|
FConnection: IDAConnection;
|
|
|
|
|
|
FPlantilla : string;
|
|
|
|
|
|
FWordApp : TWordApp;
|
|
|
|
|
|
FDocumento : TWordDoc;
|
2009-07-09 08:24:19 +00:00
|
|
|
|
// FNumCapitulos : Integer;
|
2008-02-07 22:07:23 +00:00
|
|
|
|
FCodigoFactura : string;
|
|
|
|
|
|
FNombreFichero : String;
|
2008-12-01 17:56:01 +00:00
|
|
|
|
FVerSello : Boolean;
|
2009-07-09 08:24:19 +00:00
|
|
|
|
// function DarNumCapitulos : Integer;
|
|
|
|
|
|
// procedure InsertarConceptos(Tabla : Table);
|
2008-02-07 22:07:23 +00:00
|
|
|
|
function Generar : Boolean;
|
|
|
|
|
|
function RellenarCabecera : boolean; virtual;
|
|
|
|
|
|
function RellenarInforme : boolean; virtual;
|
2008-06-11 16:35:39 +00:00
|
|
|
|
procedure _GenerarFactura(const AID: String);
|
2008-02-07 22:07:23 +00:00
|
|
|
|
public
|
2008-11-13 10:33:06 +00:00
|
|
|
|
function Exportar(Codigo, Fichero : String; const VerSello: Boolean = True): Boolean;
|
2008-02-07 22:07:23 +00:00
|
|
|
|
constructor Create (AOwner : TComponent); override;
|
|
|
|
|
|
destructor Destroy; override;
|
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
|
|
implementation
|
|
|
|
|
|
|
|
|
|
|
|
{ TRptWordFacturaCliente }
|
|
|
|
|
|
|
|
|
|
|
|
{$R *.dfm}
|
|
|
|
|
|
|
|
|
|
|
|
uses
|
|
|
|
|
|
Windows, Variants, Dialogs, uDataModuleServer, uStringsUtils, uSistemaFunc,
|
|
|
|
|
|
srvEmpresas_Impl, uROTypes, uROClasses;
|
|
|
|
|
|
|
|
|
|
|
|
const
|
2008-02-28 19:39:33 +00:00
|
|
|
|
rptInforme = 'FacturaCliente.rdx';
|
2008-02-07 22:07:23 +00:00
|
|
|
|
|
|
|
|
|
|
constructor TRptWordFacturaCliente.Create(AOwner: TComponent);
|
|
|
|
|
|
begin
|
|
|
|
|
|
inherited;
|
|
|
|
|
|
FDocumento := NIL;
|
|
|
|
|
|
end;
|
|
|
|
|
|
|
2009-07-09 08:24:19 +00:00
|
|
|
|
{function TRptWordFacturaCliente.DarNumCapitulos: Integer;
|
2008-02-07 22:07:23 +00:00
|
|
|
|
var
|
|
|
|
|
|
AuxNumCapitulos : integer;
|
|
|
|
|
|
begin
|
|
|
|
|
|
AuxNumCapitulos := 0;
|
|
|
|
|
|
tbl_Cabecera.First;
|
|
|
|
|
|
while not tbl_Cabecera.Eof do
|
|
|
|
|
|
begin
|
|
|
|
|
|
if tbl_Cabecera.FieldByName('TIPO_DETALLE').AsString = 'Titulo' then
|
|
|
|
|
|
AuxNumCapitulos := AuxNumCapitulos + 1;
|
|
|
|
|
|
tbl_Cabecera.Next;
|
|
|
|
|
|
end;
|
|
|
|
|
|
tbl_Cabecera.First;
|
|
|
|
|
|
Result := AuxNumCapitulos;
|
2009-07-09 08:24:19 +00:00
|
|
|
|
end;}
|
2008-02-07 22:07:23 +00:00
|
|
|
|
|
|
|
|
|
|
destructor TRptWordFacturaCliente.Destroy;
|
|
|
|
|
|
begin
|
|
|
|
|
|
if FDocumento <> NIL then
|
|
|
|
|
|
FDocumento.Free;
|
|
|
|
|
|
FDocumento := NIL;
|
|
|
|
|
|
inherited;
|
|
|
|
|
|
end;
|
|
|
|
|
|
|
2008-11-13 10:33:06 +00:00
|
|
|
|
function TRptWordFacturaCliente.Exportar(Codigo, Fichero: String; const VerSello: Boolean = True): Boolean;
|
2008-02-07 22:07:23 +00:00
|
|
|
|
begin
|
|
|
|
|
|
if EsCadenaVacia(Fichero) then
|
|
|
|
|
|
begin
|
|
|
|
|
|
Result := False;
|
|
|
|
|
|
raise Exception.Create('Falta indicar el fichero donde se exportar<61> el listado.');
|
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
|
|
FNombreFichero := Fichero;
|
|
|
|
|
|
FCodigoFactura := Codigo;
|
2008-12-01 17:56:01 +00:00
|
|
|
|
FVerSello := VerSello;
|
2008-02-07 22:07:23 +00:00
|
|
|
|
_GenerarFactura(Codigo);
|
|
|
|
|
|
Result := True;
|
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
|
|
procedure TRptWordFacturaCliente.DataModuleCreate(Sender: TObject);
|
|
|
|
|
|
begin
|
|
|
|
|
|
schReport.ConnectionManager := dmServer.ConnectionManager;
|
|
|
|
|
|
FConnection := dmServer.DarNuevaConexion;
|
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
|
|
function TRptWordFacturaCliente.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-02-07 22:07:23 +00:00
|
|
|
|
try
|
|
|
|
|
|
if not RellenarCabecera then
|
|
|
|
|
|
RaiseError('Se producido un error al generar la cabecera en MS Word.');
|
|
|
|
|
|
|
|
|
|
|
|
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-02-07 22:07:23 +00:00
|
|
|
|
Result := True;
|
|
|
|
|
|
finally
|
|
|
|
|
|
FDocumento := NIL;
|
|
|
|
|
|
FWordApp := NIL;
|
|
|
|
|
|
end;
|
|
|
|
|
|
end;
|
|
|
|
|
|
|
2009-07-09 08:24:19 +00:00
|
|
|
|
{procedure TRptWordFacturaCliente.InsertarConceptos(Tabla : Table);
|
2008-02-07 22:07:23 +00:00
|
|
|
|
var
|
|
|
|
|
|
numRows, numCols, mergeSplit, shiftCells : OleVariant;
|
|
|
|
|
|
iContador : Integer;
|
|
|
|
|
|
TotalConceptos : Double;
|
2009-06-02 13:59:06 +00:00
|
|
|
|
ACantidad: String;
|
|
|
|
|
|
AIndice: Integer;
|
|
|
|
|
|
AText : String;
|
2008-02-07 22:07:23 +00:00
|
|
|
|
begin
|
2009-07-09 08:24:19 +00:00
|
|
|
|
TotalConceptos := 0;
|
2008-02-07 22:07:23 +00:00
|
|
|
|
numRows := 2;
|
|
|
|
|
|
numCols := 1;
|
|
|
|
|
|
mergeSplit := False;
|
|
|
|
|
|
shiftCells := False;
|
|
|
|
|
|
iContador := 2; // Empezar en la 2<> fila de celdas. La primera es la
|
|
|
|
|
|
// cabecera de la tabla.
|
|
|
|
|
|
|
|
|
|
|
|
with Tabla, tbl_Detalles do
|
|
|
|
|
|
begin
|
|
|
|
|
|
while not EOF do
|
|
|
|
|
|
begin
|
|
|
|
|
|
if FieldByName('TIPO_DETALLE').AsString <> 'Concepto' then
|
|
|
|
|
|
Break;
|
|
|
|
|
|
// Partir la celda actual en 2 filas de 1 columna.
|
|
|
|
|
|
Rows.Item(iContador).Cells.Split (numRows, numCols, mergesplit);
|
|
|
|
|
|
Cell(iContador, 1).Range.Text := FieldByName('CONCEPTO').AsString;
|
2009-06-02 13:59:06 +00:00
|
|
|
|
|
|
|
|
|
|
ACantidad := FloatToStr(FieldByName('CANTIDAD').AsFloat);
|
|
|
|
|
|
AIndice := Pos(',', ACantidad);
|
|
|
|
|
|
if AIndice > 0 then
|
|
|
|
|
|
AText := FormatFloat('#,0.00', FieldByName('CANTIDAD').AsFloat)
|
|
|
|
|
|
else
|
|
|
|
|
|
AText := FormatFloat('#,0.##', FieldByName('CANTIDAD').AsFloat);
|
|
|
|
|
|
|
|
|
|
|
|
Cell(iContador, 2).Range.Text := AText;
|
|
|
|
|
|
|
2009-03-03 16:07:16 +00:00
|
|
|
|
|
|
|
|
|
|
if (FieldByName('IMPORTE_UNIDAD').AsFloat = 0) then
|
|
|
|
|
|
Cell(iContador, 3).Range.Text := ''
|
|
|
|
|
|
else
|
|
|
|
|
|
Cell(iContador, 3).Range.Text := FormatFloat(DISPLAY_EUROS2, FieldByName('IMPORTE_UNIDAD').AsFloat);
|
|
|
|
|
|
|
|
|
|
|
|
if (FieldByName('IMPORTE_TOTAL').AsFloat = 0) then
|
|
|
|
|
|
Cell(iContador, 4).Range.Text := ''
|
|
|
|
|
|
else
|
|
|
|
|
|
Cell(iContador, 4).Range.Text := FormatFloat(DISPLAY_EUROS2, FieldByName('IMPORTE_TOTAL').AsFloat);
|
|
|
|
|
|
|
2008-02-07 22:07:23 +00:00
|
|
|
|
TotalConceptos := TotalConceptos + FieldByName('IMPORTE_TOTAL').AsFloat;
|
|
|
|
|
|
Next;
|
|
|
|
|
|
Inc (iContador);
|
|
|
|
|
|
end;
|
|
|
|
|
|
// Borrar la fila vac<61>a que sobra
|
|
|
|
|
|
Rows.Item(iContador).Cells.Delete(shiftCells);
|
|
|
|
|
|
Cell(iContador, 1).Range.Text := 'Total: ' + FormatFloat(DISPLAY_EUROS2, TotalConceptos);
|
|
|
|
|
|
AutoFitBehavior(wdAutoFitWindow);
|
|
|
|
|
|
end;
|
2009-07-09 08:24:19 +00:00
|
|
|
|
end;}
|
2008-02-07 22:07:23 +00:00
|
|
|
|
|
|
|
|
|
|
function TRptWordFacturaCliente.RellenarCabecera: boolean;
|
|
|
|
|
|
var
|
|
|
|
|
|
NombreFichero,
|
|
|
|
|
|
Texto,
|
2009-07-09 08:24:19 +00:00
|
|
|
|
// FicheroTemporal : String;
|
|
|
|
|
|
// LinkToFile, SaveWithDocument, _Range : OleVariant;
|
|
|
|
|
|
// Imagen : InlineShape;
|
2008-02-07 22:07:23 +00:00
|
|
|
|
_ShiftCells : OleVariant;
|
2008-02-28 19:39:33 +00:00
|
|
|
|
ImporteAux : Double;
|
2008-06-11 16:35:39 +00:00
|
|
|
|
Cadena : String;
|
2008-02-07 22:07:23 +00:00
|
|
|
|
begin
|
|
|
|
|
|
|
|
|
|
|
|
//PARA DIBUJAR EL LOGOTIPO MULTIEMPRESA
|
|
|
|
|
|
{--------------------------- PENDIENTE
|
|
|
|
|
|
if (EmpresaActiva.Logotipo <> Nil) then
|
|
|
|
|
|
begin
|
|
|
|
|
|
//Activamos cabecera
|
|
|
|
|
|
FWordApp.Application.ActiveWindow.ActivePane.View.SeekView := wdSeekCurrentPageHeader;
|
|
|
|
|
|
LinkToFile := False;
|
|
|
|
|
|
SaveWithDocument := True;
|
|
|
|
|
|
_Range := EmptyParam;
|
|
|
|
|
|
FicheroTemporal := DarFicheroTemporal;
|
|
|
|
|
|
EmpresaActiva.Logotipo.SaveToFile (FicheroTemporal);
|
|
|
|
|
|
Imagen := FWordApp.Application.ActiveWindow.ActivePane.Selection.InlineShapes.AddPicture(ficherotemporal, LinkToFile, SaveWithDocument, _Range);
|
|
|
|
|
|
|
|
|
|
|
|
//Formateamos imagen
|
|
|
|
|
|
if ((Imagen.Get_Width > ANCHO_LOGO_INF)) then
|
|
|
|
|
|
begin
|
|
|
|
|
|
Imagen.Set_Height(((ANCHO_LOGO_INF * Imagen.Get_Height) /Imagen.Get_Width));
|
|
|
|
|
|
Imagen.Set_Width(ANCHO_LOGO_INF);
|
|
|
|
|
|
end;
|
|
|
|
|
|
end;
|
|
|
|
|
|
---------------------------- }
|
2008-06-11 16:35:39 +00:00
|
|
|
|
|
2008-02-07 22:07:23 +00:00
|
|
|
|
with FDocumento, tbl_Cabecera do
|
|
|
|
|
|
begin
|
2008-02-28 19:39:33 +00:00
|
|
|
|
//Activamos cabecera
|
|
|
|
|
|
FWordApp.Application.ActiveWindow.ActivePane.View.SeekView := wdSeekCurrentPageHeader;
|
|
|
|
|
|
|
2008-06-11 11:51:50 +00:00
|
|
|
|
if (FieldByName('TIPO').AsString = 'F') then
|
2009-01-08 12:49:50 +00:00
|
|
|
|
ReplaceBookmark('CodigoFacturaCab', FieldByName('REFERENCIA').AsString)
|
2008-06-11 11:51:50 +00:00
|
|
|
|
else
|
2009-01-08 12:49:50 +00:00
|
|
|
|
ReplaceBookmark('CodigoFacturaCab', FieldByName('REFERENCIA').AsString);
|
2008-02-07 22:07:23 +00:00
|
|
|
|
ReplaceBookmark('FechaFacturaCab', FieldByName('FECHA_FACTURA').AsString);
|
2008-06-11 16:35:39 +00:00
|
|
|
|
|
2009-01-15 18:49:02 +00:00
|
|
|
|
//Se cambia se omiten los vencimientos de los recibos solo tendremos en cuenta el de la factura
|
|
|
|
|
|
Cadena := FieldByName('FECHA_VENCIMIENTO').AsString;
|
|
|
|
|
|
{ tbl_Vencimientos.First;
|
2008-06-11 16:35:39 +00:00
|
|
|
|
Cadena := '';
|
|
|
|
|
|
while not tbl_Vencimientos.eof do
|
|
|
|
|
|
begin
|
|
|
|
|
|
Cadena := Cadena + tbl_Vencimientos.FieldByName('FECHA_VENCIMIENTO').AsString + ' ';
|
|
|
|
|
|
tbl_Vencimientos.Next;
|
|
|
|
|
|
end;
|
2009-01-15 18:49:02 +00:00
|
|
|
|
}
|
2008-06-11 16:35:39 +00:00
|
|
|
|
|
|
|
|
|
|
ReplaceBookmark('VencimientoCab', Cadena);
|
2008-02-07 22:07:23 +00:00
|
|
|
|
ReplaceBookmark('FormaPagoCab', FieldByName('FORMA_PAGO').AsString);
|
2008-06-05 18:21:13 +00:00
|
|
|
|
ReplaceBookmark('BancoCab', FieldByName('DATOS_BANCARIOS').AsString);
|
2008-02-07 22:07:23 +00:00
|
|
|
|
|
|
|
|
|
|
ReplaceBookmark('NombreClienteCab', FieldByName('NOMBRE').AsString);
|
|
|
|
|
|
ReplaceBookmark('CIFClienteCab', FieldByName('NIF_CIF').AsString);
|
|
|
|
|
|
|
|
|
|
|
|
ReplaceBookmark('DireccionClienteCab', FieldByName('CALLE').AsString);
|
|
|
|
|
|
ReplaceBookmark('PoblacionClienteCab',
|
|
|
|
|
|
FieldByName('CODIGO_POSTAL').AsString + ' ' +
|
|
|
|
|
|
FieldByName('POBLACION').AsString + ' ' + FieldByName('PROVINCIA').AsString);
|
|
|
|
|
|
|
2009-01-15 18:49:02 +00:00
|
|
|
|
ReplaceBookmark('BaseImponible', FormatFloat(DISPLAY_EUROS2, FieldByName('IMPORTE_NETO').AsFloat));
|
|
|
|
|
|
ImporteAux := FieldByName('BASE_IMPONIBLE').AsFloat; // - FieldByName('IMPORTE_DESCUENTO').AsFloat;
|
2008-02-28 19:39:33 +00:00
|
|
|
|
ReplaceBookmark('BaseImponible2', FormatFloat(DISPLAY_EUROS2, ImporteAux));
|
2008-02-07 22:07:23 +00:00
|
|
|
|
|
|
|
|
|
|
if (FieldByName('DESCUENTO').AsInteger = 0) then
|
|
|
|
|
|
begin
|
|
|
|
|
|
ReplaceBookmark('BaseImponibleTexto', 'Base imponible');
|
|
|
|
|
|
FWordApp.GotoBookmark('CeldasDescuento');
|
|
|
|
|
|
_ShiftCells := wdDeleteCellsShiftLeft;
|
|
|
|
|
|
FWordApp.Application.Selection.Cells.Delete(_ShiftCells);
|
|
|
|
|
|
end
|
|
|
|
|
|
else begin
|
|
|
|
|
|
ReplaceBookmark('Descuento', FieldByName('DESCUENTO').AsString);
|
|
|
|
|
|
ReplaceBookmark('ImporteDto', FormatFloat(DISPLAY_EUROS2, FieldByName('IMPORTE_DESCUENTO').AsFloat));
|
|
|
|
|
|
end;
|
|
|
|
|
|
if EsCadenaVacia(FieldByName('IVA').AsString) then
|
|
|
|
|
|
ReplaceBookmark('IVA', '0')
|
|
|
|
|
|
else
|
|
|
|
|
|
ReplaceBookmark('IVA', FieldByName('IVA').AsString);
|
|
|
|
|
|
ReplaceBookmark('ImporteIVA', FormatFloat(DISPLAY_EUROS2, FieldByName('IMPORTE_IVA').AsFloat));
|
|
|
|
|
|
ReplaceBookmark('ImporteTotal', FormatFloat(DISPLAY_EUROS2, FieldByName('IMPORTE_TOTAL').AsFloat));
|
|
|
|
|
|
|
2009-01-15 18:49:02 +00:00
|
|
|
|
if (FieldByName('RETENCION').AsInteger = 0) then
|
|
|
|
|
|
begin
|
|
|
|
|
|
FWordApp.GotoBookmark('CeldasRetencion');
|
|
|
|
|
|
_ShiftCells := wdDeleteCellsShiftLeft;
|
|
|
|
|
|
FWordApp.Application.Selection.Cells.Delete(_ShiftCells);
|
|
|
|
|
|
end
|
|
|
|
|
|
else begin
|
2009-01-16 20:07:01 +00:00
|
|
|
|
ReplaceBookmark('TituloImporteTotal', 'Total certificacion');
|
2009-01-15 18:49:02 +00:00
|
|
|
|
ReplaceBookmark('Retencion', FieldByName('RETENCION').AsString);
|
|
|
|
|
|
ReplaceBookmark('ImporteRetencion', FormatFloat(DISPLAY_EUROS2, FieldByName('IMPORTE_RETENCION').AsFloat));
|
2009-01-16 20:07:01 +00:00
|
|
|
|
ReplaceBookmark('ImporteTotalRet', FormatFloat(DISPLAY_EUROS2, (FieldByName('IMPORTE_TOTAL').AsFloat - FieldByName('IMPORTE_RETENCION').AsFloat)));
|
2009-01-15 18:49:02 +00:00
|
|
|
|
end;
|
|
|
|
|
|
|
2008-02-07 22:07:23 +00:00
|
|
|
|
Texto := FieldByName('OBSERVACIONES').AsString;
|
|
|
|
|
|
if not EsCadenaVacia(Texto) then
|
|
|
|
|
|
begin
|
|
|
|
|
|
NombreFichero := DarFicheroTemporal;
|
|
|
|
|
|
EscribirEnFichero(NombreFichero, Texto);
|
|
|
|
|
|
FWordApp.InsertFile(NombreFichero, 'Descripcion');
|
|
|
|
|
|
SysUtils.DeleteFile(NombreFichero);
|
|
|
|
|
|
end;
|
|
|
|
|
|
|
2013-02-26 17:58:56 +00:00
|
|
|
|
if (tbl_Cabecera.FieldByName('ID_EMPRESA').AsInteger <> 3) then
|
|
|
|
|
|
begin
|
|
|
|
|
|
ReplaceBookmark('NombreEmpresa', tbl_Empresa.FieldByName('NOMBRE').AsString);
|
|
|
|
|
|
ReplaceBookmark('CifEmpresa', tbl_Empresa.FieldByName('NIF_CIF').AsString);
|
|
|
|
|
|
ReplaceBookmark('DireccionEmpresa',
|
|
|
|
|
|
Format('%s. %s %s', [tbl_Empresa.FieldByName('CALLE').AsString,
|
|
|
|
|
|
tbl_Empresa.FieldByName('CODIGO_POSTAL').AsString, tbl_Empresa.FieldByName('POBLACION').AsString]));
|
|
|
|
|
|
ReplaceBookmark('TelefonoEmpresa', tbl_Empresa.FieldByName('TELEFONO_1').AsString);
|
|
|
|
|
|
ReplaceBookmark('FaxEmpresa', tbl_Empresa.FieldByName('FAX').AsString);
|
|
|
|
|
|
ReplaceBookmark('CorreoEmpresa', tbl_Empresa.FieldByName('EMAIL_1').AsString);
|
|
|
|
|
|
ReplaceBookmark('DatosRegistroMercantil', tbl_Empresa.FieldByName('REGISTRO_MERCANTIL').AsString);
|
|
|
|
|
|
end;
|
2008-12-01 17:56:01 +00:00
|
|
|
|
|
|
|
|
|
|
if not FVerSello then
|
2013-04-12 16:19:42 +00:00
|
|
|
|
ReplaceBookmark('Sello', '');
|
2008-12-01 17:56:01 +00:00
|
|
|
|
|
2014-02-18 22:41:52 +00:00
|
|
|
|
if (tbl_Cabecera.FieldByName('CERTIFICADO_ISO').AsInteger <> 1) then
|
|
|
|
|
|
begin
|
|
|
|
|
|
ReplaceBookmark('ISO', '');
|
|
|
|
|
|
end;
|
|
|
|
|
|
|
2008-02-07 22:07:23 +00:00
|
|
|
|
Close;
|
|
|
|
|
|
end;
|
2013-04-12 16:19:42 +00:00
|
|
|
|
|
2008-02-07 22:07:23 +00:00
|
|
|
|
Result := True;
|
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
|
|
function TRptWordFacturaCliente.RellenarInforme : boolean;
|
|
|
|
|
|
var
|
|
|
|
|
|
numRows, numCols, mergesplit : OleVariant;
|
|
|
|
|
|
iRowCount : Integer;
|
|
|
|
|
|
TipoConAnterior : String;
|
|
|
|
|
|
Seleccion : TWordRange;
|
|
|
|
|
|
TotalCapitulo : Double;
|
|
|
|
|
|
EsCapitulo : Boolean;
|
2009-06-02 13:59:06 +00:00
|
|
|
|
ACantidad: String;
|
|
|
|
|
|
AIndice: Integer;
|
|
|
|
|
|
AText : String;
|
2008-02-07 22:07:23 +00:00
|
|
|
|
begin
|
|
|
|
|
|
Result := False;
|
|
|
|
|
|
iRowCount := 2;
|
|
|
|
|
|
numrows := 2;
|
|
|
|
|
|
numcols := 1;
|
|
|
|
|
|
mergeSplit := False;
|
|
|
|
|
|
TipoConAnterior := '';
|
|
|
|
|
|
TotalCapitulo := 0;
|
|
|
|
|
|
EsCapitulo := False;
|
|
|
|
|
|
|
|
|
|
|
|
with FDocumento.Document.Tables.Item(1), tbl_detalles do
|
|
|
|
|
|
begin
|
|
|
|
|
|
First;
|
|
|
|
|
|
while not tbl_detalles.EOF do
|
|
|
|
|
|
begin
|
|
|
|
|
|
if (TipoConAnterior = 'Concepto') and (FieldByName('TIPO_DETALLE').AsString = 'Titulo') then
|
|
|
|
|
|
begin
|
|
|
|
|
|
Rows.Item (iRowCount).Cells.Split (numRows, numCols, mergesplit);
|
|
|
|
|
|
if EsCapitulo then
|
|
|
|
|
|
begin
|
|
|
|
|
|
Rows.Item (iRowCount).Cells.Split (numRows, numCols, mergesplit);
|
|
|
|
|
|
Cell(iRowCount, 2).Range.Text := 'TOTAL DEL CAP<41>TULO';
|
|
|
|
|
|
Cell(iRowCount, 5).Range.Text := FormatFloat(DISPLAY_EUROS2, TotalCapitulo);
|
|
|
|
|
|
TotalCapitulo := 0;
|
|
|
|
|
|
Inc (iRowCount);
|
|
|
|
|
|
end;
|
|
|
|
|
|
Inc (iRowCount);
|
|
|
|
|
|
end;
|
|
|
|
|
|
Rows.Item (iRowCount).Cells.Split (numRows, numCols, mergesplit);
|
|
|
|
|
|
if FieldByName('TIPO_DETALLE').AsString = 'Titulo' then
|
|
|
|
|
|
begin
|
|
|
|
|
|
Cell(iRowCount, 2).Range.Text := FieldByName('CONCEPTO').AsString;
|
|
|
|
|
|
Rows.Item(iRowCount).Select;
|
|
|
|
|
|
Seleccion := FDocumento.AddRangeFromSelection;
|
|
|
|
|
|
Seleccion.Bold := True;
|
|
|
|
|
|
TotalCapitulo := 0;
|
|
|
|
|
|
EsCapitulo := True;
|
|
|
|
|
|
end
|
|
|
|
|
|
else begin
|
|
|
|
|
|
Cell(iRowCount, 1).Range.Text := FieldByName('REFERENCIA').AsString;
|
|
|
|
|
|
Cell(iRowCount, 2).Range.Text := FieldByName('CONCEPTO').AsString;
|
2009-06-02 13:59:06 +00:00
|
|
|
|
|
|
|
|
|
|
ACantidad := FloatToStr(FieldByName('CANTIDAD').AsFloat);
|
2009-09-01 16:43:02 +00:00
|
|
|
|
if ACantidad = '0' then
|
|
|
|
|
|
AText := ''
|
|
|
|
|
|
else begin
|
|
|
|
|
|
AIndice := Pos(',', ACantidad);
|
|
|
|
|
|
if AIndice > 0 then
|
|
|
|
|
|
AText := FormatFloat('#,0.00', FieldByName('CANTIDAD').AsFloat)
|
|
|
|
|
|
else
|
|
|
|
|
|
AText := FormatFloat('#,0.##', FieldByName('CANTIDAD').AsFloat);
|
|
|
|
|
|
end;
|
2009-06-02 13:59:06 +00:00
|
|
|
|
|
|
|
|
|
|
Cell(iRowCount, 3).Range.Text := AText + ' ' + FieldByName('UNIDAD_MEDIDA').AsString;
|
2009-09-01 16:43:02 +00:00
|
|
|
|
if FieldByName('IMPORTE_UNIDAD').AsFloat <> 0 then
|
2013-01-09 18:16:07 +00:00
|
|
|
|
Cell(iRowCount, 4).Range.Text := FormatFloat(DISPLAY_EUROS4, FieldByName('IMPORTE_UNIDAD').AsFloat);
|
2009-09-01 16:43:02 +00:00
|
|
|
|
|
|
|
|
|
|
if FieldByName('IMPORTE_TOTAL').AsFloat <> 0 then
|
2013-01-09 18:16:07 +00:00
|
|
|
|
Cell(iRowCount, 5).Range.Text := FormatFloat(DISPLAY_EUROS4, FieldByName('IMPORTE_TOTAL').AsFloat);
|
2009-09-01 16:43:02 +00:00
|
|
|
|
|
2008-02-07 22:07:23 +00:00
|
|
|
|
TotalCapitulo := TotalCapitulo + FieldByName('IMPORTE_TOTAL').AsFloat;
|
|
|
|
|
|
end;
|
|
|
|
|
|
TipoConAnterior := FieldByName('TIPO_DETALLE').AsString;
|
|
|
|
|
|
Next;
|
|
|
|
|
|
Inc (iRowCount);
|
|
|
|
|
|
end;
|
|
|
|
|
|
if EsCapitulo then
|
|
|
|
|
|
begin
|
|
|
|
|
|
Rows.Item (iRowCount).Cells.Split (numRows, numCols, mergesplit);
|
|
|
|
|
|
Cell(iRowCount, 2).Range.Text := 'TOTAL DEL CAP<41>TULO';
|
|
|
|
|
|
Cell(iRowCount, 5).Range.Text := FormatFloat(DISPLAY_EUROS2, TotalCapitulo);
|
|
|
|
|
|
TotalCapitulo := 0;
|
|
|
|
|
|
end;
|
|
|
|
|
|
Close;
|
|
|
|
|
|
end;
|
|
|
|
|
|
Result := True;
|
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
|
|
procedure TRptWordFacturaCliente._GenerarFactura(const AID: String);
|
|
|
|
|
|
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').AsString := AID;
|
|
|
|
|
|
tbl_Detalles.ParamByName('ID_FACTURA').AsString := AID;
|
|
|
|
|
|
tbl_Vencimientos.ParamByName('ID_FACTURA').AsString := AID;
|
2008-02-07 22:07:23 +00:00
|
|
|
|
|
2008-10-31 18:16:49 +00:00
|
|
|
|
tbl_Cabecera.Active := True;
|
|
|
|
|
|
tbl_Detalles.Active := True;
|
|
|
|
|
|
tbl_Vencimientos.Active := True;
|
2008-02-07 22:07:23 +00:00
|
|
|
|
|
2008-11-03 18:58:28 +00:00
|
|
|
|
FPlantilla := DarRutaInformes + tbl_Cabecera.FieldByName('ID_EMPRESA').AsString + '\' + rptInforme;
|
|
|
|
|
|
|
2008-10-31 18:16:49 +00:00
|
|
|
|
FCodigoFactura := AID;
|
2008-02-07 22:07:23 +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-02-28 19:39:33 +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-02-07 22:07:23 +00:00
|
|
|
|
end;
|
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
end.
|