Vista de detalles:

- Habilitado columna descuento
- Habilitado tipo de fila (titulo, concepto, pie, subtotal). 

git-svn-id: https://192.168.0.254/svn/Proyectos.Acana_FactuGES2/trunk@75 f4e31baf-9722-1c47-927c-6f952f962d4b
This commit is contained in:
David Arranz 2008-01-02 10:43:52 +00:00
parent 1d8e13ce8a
commit cbc2ba3d36

View File

@ -9,6 +9,7 @@ const
TIPO_DETALLE_TITULO = 'Titulo';
TIPO_DETALLE_SUBTOTAL = 'Subtotal';
TIPO_DETALLE_SALTO = 'Salto';
TIPO_DETALLE_DESCUENTO = 'Descuento';
CTE_DESC_SALTO = 'SALTO DE PAGINA >>';
@ -29,7 +30,7 @@ type
procedure ActualizarTotales(ADataTable: IDAStronglyTypedDataTable);
function DarTotalImporteTotal(ADataTable: IDAStronglyTypedDataTable): Double;
function LocalizarPosicion(ADataTable: IDAStronglyTypedDataTable; const APosicion: Integer): Boolean;
function DarListaTiposDetalle: TStringList;
end;
@ -59,6 +60,9 @@ type
procedure CalculoDetalleTitulo(DataTable: TDADataTable; var ImporteAcumulado : Double; var ImporteTotal : Double); virtual;
procedure TratamientoDetalleSubtotal(DataTable: TDADataTable); virtual;
procedure CalculoDetalleSubtotal(DataTable: TDADataTable; var ImporteAcumulado : Double; var ImporteTotal : Double); virtual;
procedure TratamientoDetalleDescuento(DataTable: TDADataTable); virtual;
procedure CalculoDetalleDescuento(DataTable: TDADataTable; var ImporteAcumulado : Double; var ImporteTotal : Double); virtual;
//Si sobreescribimos este metodo es para continuar el CalcularTotales segun los tipos de concepto de los hijos
function CalcularTotalesHijos(Modificar: boolean; DataTable: TDADataTable; var ImporteAcumulado : Double; var ImporteTotal : Double): Double; virtual;
@ -78,6 +82,7 @@ type
procedure ActualizarTotales(ADataTable: IDAStronglyTypedDataTable);
function DarTotalImporteTotal(ADataTable: IDAStronglyTypedDataTable): Double;
function DarListaTiposDetalle: TStringList; virtual;
function LocalizarPosicion(ADataTable: IDAStronglyTypedDataTable; const APosicion: Integer): Boolean;
end;
@ -85,7 +90,8 @@ implementation
{ TControllerDetallesBase }
uses cxControls, SysUtils, DB, uDAInterfaces;
uses
cxControls, SysUtils, DB, uDAInterfaces, Dialogs;
procedure TControllerDetallesBase.ActualizarTotales(ADataTable: IDAStronglyTypedDataTable);
begin
@ -149,6 +155,7 @@ begin
ValidarCampos(DataTable);
DataTable.DisableControls;
AuxPosicionIni := DataTable.FieldByName(CAMPO_POSICION).AsInteger;
AuxPosicion := 0;
AuxImporteAcumulado := 0;
@ -156,7 +163,7 @@ begin
try
DataTable.First;
while DataTable.Locate(CAMPO_POSICION, IntToStr(AuxPosicion), []) do
while DataTable.Locate(CAMPO_POSICION, AuxPosicion, []) do
begin
//SALTOS DE LINEA
if (DataTable.FieldByName(CAMPO_TIPO).AsString = TIPO_DETALLE_SALTO) then
@ -172,13 +179,20 @@ begin
TratamientoDetalleTitulo(DataTable); //Se podrá sobreescribir para que se tengan en cuenta nuevos campos en hijos
CalculoDetalleTitulo(DataTable, AuxImporteAcumulado, AuxImporteTotal); //Se podrá sobreescribir para posibles nuevos calculos de los hijos
end
//SUBTITULOS
//SUBTOTAL
else if (DataTable.FieldByName(CAMPO_TIPO).AsString = TIPO_DETALLE_SUBTOTAL) then
begin
if Modificar then
TratamientoDetalleSubtotal(DataTable); //Se podrá sobreescribir para que se tengan en cuenta nuevos campos
CalculoDetalleSubtotal(DataTable, AuxImporteAcumulado, AuxImporteTotal); //Se podrá sobreescribir para posibles nuevos calculos de los hijos
end
//DESCUENTO DE CAPITULO
else if (DataTable.FieldByName(CAMPO_TIPO).AsString = TIPO_DETALLE_DESCUENTO) then
begin
if Modificar then
TratamientoDetalleDescuento(DataTable); //Se podrá sobreescribir para que se tengan en cuenta nuevos campos
CalculoDetalleDescuento(DataTable, AuxImporteAcumulado, AuxImporteTotal); //Se podrá sobreescribir para posibles nuevos calculos de los hijos
end
//CONCEPTOS
else if (DataTable.FieldByName(CAMPO_TIPO).AsString = TIPO_DETALLE_CONCEPTO) then
begin
@ -195,7 +209,7 @@ begin
finally
//Dejamos el puntero en la misma posición que la que partió
DataTable.Locate(CAMPO_POSICION, IntToStr(AuxPosicionIni), []);
DataTable.Locate(CAMPO_POSICION, AuxPosicionIni, []);
DataTable.EnableControls;
end;
@ -217,6 +231,21 @@ begin
end;
end;
procedure TControllerDetallesBase.CalculoDetalleDescuento(
DataTable: TDADataTable; var ImporteAcumulado, ImporteTotal: Double);
var
ImporteDto : Double;
begin
with DataTable do
begin
if not Editing then Edit;
ImporteDto := (-1)*((ImporteTotal * DataTable.FieldByName(CAMPO_DESCUENTO).AsFloat) / 100);
ImporteTotal := ImporteTotal + ImporteDto;
FieldByName(CAMPO_IMPORTE_TOTAL).AsFloat := ImporteTotal;
Post;
end;
end;
procedure TControllerDetallesBase.CalculoDetalleSalto(DataTable: TDADataTable; var ImporteAcumulado, ImporteTotal: Double);
begin
with DataTable do
@ -258,13 +287,14 @@ end;
function TControllerDetallesBase.DarListaTiposDetalle: TStringList;
begin
Result := TStringList.Create;
Result.Values[TIPO_DETALLE_CONCEPTO] := 'Concepto';
Result.Values[TIPO_DETALLE_TITULO] := 'Título de capítulo';
Result.Values[TIPO_DETALLE_SUBTOTAL] := 'Final de capítulo';
Result.Values[TIPO_DETALLE_SALTO] := 'Salto de página';
Result.Values[TIPO_DETALLE_CONCEPTO] := TIPO_DETALLE_CONCEPTO;
Result.Values[TIPO_DETALLE_TITULO] := TIPO_DETALLE_TITULO;
Result.Values[TIPO_DETALLE_SUBTOTAL] := TIPO_DETALLE_SUBTOTAL;
Result.Values[TIPO_DETALLE_DESCUENTO] := TIPO_DETALLE_DESCUENTO;
Result.Values[TIPO_DETALLE_SALTO] := TIPO_DETALLE_SALTO;
end;
function TControllerDetallesBase.darTotalImporteTotal(ADataTable: IDAStronglyTypedDataTable): Double;
function TControllerDetallesBase.DarTotalImporteTotal(ADataTable: IDAStronglyTypedDataTable): Double;
begin
Result := CalcularTotales(False, ADataTable.DataTable);
end;
@ -288,7 +318,7 @@ begin
begin
DataTable.First;
DeletePosicion := POSICION[i];
if DataTable.Locate(CAMPO_POSICION, IntToStr(DeletePosicion), []) then
if DataTable.Locate(CAMPO_POSICION, DeletePosicion, []) then
DataTable.Delete;
end;
Renumerar(DataTable, DeletePosicion);
@ -375,12 +405,12 @@ begin
posIni := DataTable.FieldByName(CAMPO_POSICION).AsInteger;
DataTable.First;
if DataTable.Locate(CAMPO_POSICION, IntToStr(pPosicion), []) then
if DataTable.Locate(CAMPO_POSICION, pPosicion, []) then
Result := DataTable.FieldByName(CAMPO_TIPO).AsString;
//Volvemos a posicionar el puntero donde estaba
DataTable.First;
if not DataTable.Locate(CAMPO_POSICION, IntToStr(posIni), []) then
if not DataTable.Locate(CAMPO_POSICION, posIni, []) then
raise Exception.Create('La posición ' + IntToStr(posIni) + ' no existe (getTipo)');
end;
finally
@ -388,6 +418,32 @@ begin
end;
end;
function TControllerDetallesBase.LocalizarPosicion(
ADataTable: IDAStronglyTypedDataTable; const APosicion: Integer): Boolean;
var
AField: TDAField;
begin
AField := ADataTable.DataTable.FindField(CAMPO_POSICION);
if not Assigned(AField) then
raise Exception.Create('Campo ' + CAMPO_POSICION + ' no encontrado (LocalizarPosicion)');
with ADataTable.DataTable do
begin
DisableControls;
DisableEventHandlers;
ShowHourglassCursor;
try
First;
Result := Locate(CAMPO_POSICION, APosicion, []);
finally
HideHourglassCursor;
EnableEventHandlers;
EnableControls;
end;
end;
end;
procedure TControllerDetallesBase.Move(ADataTable: IDAStronglyTypedDataTable; Posicion: TIntegerArray; Posiciones: Integer);
var
i:Integer;
@ -431,7 +487,7 @@ begin
//Buscamos el elemento con la posicion pasada por parametro
DataTable.First;
if not DataTable.Locate(CAMPO_POSICION, IntToStr(Posicion), []) then
if not DataTable.Locate(CAMPO_POSICION, Posicion, []) then
raise Exception.Create('Error, no se ha encontrado la POSICION [' + IntToStr(Posicion) + '] (mover)');
//Guardamos el id del elemento a cambiar de posicion y calculamos su nueva posicion
@ -439,14 +495,14 @@ begin
AuxOrden := Posicion + NumPosiciones;
DataTable.First;
if DataTable.Locate(CAMPO_POSICION, IntToStr(AuxOrden), []) then
if DataTable.Locate(CAMPO_POSICION, AuxOrden, []) then
begin
if not DataTable.Editing then DataTable.Edit;
DataTable.FieldByName(CAMPO_POSICION).AsInteger := DataTable.FieldByName(CAMPO_POSICION).AsInteger - NumPosiciones;
//Se hace dentro por si es el ultimo o el primero
DataTable.First;
if not DataTable.Locate(CAMPO_ID, IntToStr(AuxID), []) then
if not DataTable.Locate(CAMPO_ID, AuxID, []) then
raise Exception.Create('Error, no se ha encontrado el ID [' + IntToStr(AuxID) + '] (mover)');
if not DataTable.Editing then DataTable.Edit;
@ -457,7 +513,7 @@ begin
//Colocamos el puntero en la posición en la que estaba
DataTable.First;
DataTable.Locate(CAMPO_ID, IntToStr(AuxID), []);
DataTable.Locate(CAMPO_ID, AuxID, []);
end;
procedure TControllerDetallesBase.Renumerar(DataTable: TDADataTable; LocalizaPosicion: Integer);
@ -469,6 +525,7 @@ var
AField: TDAField;
begin
AField := DataTable.FindField(CAMPO_POSICION);
if not Assigned(AField) then
raise Exception.Create('Campo ' + CAMPO_POSICION + ' no encontrado (renumerar)');
@ -477,11 +534,11 @@ begin
for i:=0 to RecordCount-1 do
begin
First;
if not Locate(CAMPO_POSICION, IntToStr(i), []) then
if not Locate(CAMPO_POSICION, i, []) then
begin
j := i;
First;
while not Locate(CAMPO_POSICION, IntToStr(j), []) do
while not Locate(CAMPO_POSICION, j, []) do
begin
Inc(j);
First;
@ -494,7 +551,7 @@ begin
end;
//Posicionamos el puntero en la posición dada por parametro
if Locate(CAMPO_POSICION, IntToStr(LocalizaPosicion), []) then
Locate(CAMPO_POSICION, LocalizaPosicion, []);
end;
end;
@ -512,6 +569,21 @@ begin
end;
end;
procedure TControllerDetallesBase.TratamientoDetalleDescuento(
DataTable: TDADataTable);
begin
with DataTable do
begin
if not Editing then Edit;
if (FieldByName(CAMPO_CONCEPTO).AsString = CTE_DESC_SALTO) then
FieldByName(CAMPO_CONCEPTO).AsVariant := Null;
FieldByName(CAMPO_CANTIDAD).AsVariant := Null;
FieldByName(CAMPO_IMPORTE_UNIDAD).AsVariant := Null;
FieldByName(CAMPO_IMPORTE_TOTAL).AsVariant := Null;
Post;
end;
end;
procedure TControllerDetallesBase.TratamientoDetalleSalto(DataTable: TDADataTable);
begin
with DataTable do