git-svn-id: https://192.168.0.254/svn/Proyectos.Tecsitel_FactuGES2/trunk@516 0c75b7a4-871f-7646-8a2f-f78d34cc349f
166 lines
6.5 KiB
ObjectPascal
166 lines
6.5 KiB
ObjectPascal
unit uDetallesPresupuestoClienteController;
|
|
|
|
interface
|
|
|
|
uses
|
|
uDADataTable, uControllerDetallesArticulos, uBizDetallesPresupuestoCliente, uIDataModulePresupuestosCliente,
|
|
uBizArticulos, uBizContactos;
|
|
|
|
type
|
|
IDetallesPresupuestoClienteController = interface(IControllerDetallesArticulos)
|
|
['{8D1D3559-E695-4962-9999-404B26B50D6C}']
|
|
procedure AnadirArticulos(ADetalles: IDAStronglyTypedDataTable; ACliente: IBizCliente; const ANuevaFila :Boolean = True); overload;
|
|
procedure ActualizarDetalles(ADetalles: IDAStronglyTypedDataTable; ACliente: IBizCliente); overload;
|
|
procedure DesglosarPorteDetalles(ImportePorte: Currency; ADetalles: IDAStronglyTypedDataTable);
|
|
function DarTotalPorteTotal(ADetalles: IDAStronglyTypedDataTable): Double;
|
|
end;
|
|
|
|
TDetallesPresupuestoClienteController = class(TControllerDetallesArticulos, IDetallesPresupuestoClienteController)
|
|
private
|
|
FDataModule : IDataModulePresupuestosCliente;
|
|
protected
|
|
// procedure AsignarDatos(ADetalles: IDAStronglyTypedDataTable; IDCabecera: Integer); override;
|
|
procedure RellenarOtros(ADetalles: IDAStronglyTypedDataTable; AArticulos: IBizArticulo); overload; override;
|
|
procedure RellenarImportes(ADetalles: IDAStronglyTypedDataTable; AArticulos: IBizArticulo); override;
|
|
|
|
procedure AsignarController; override;
|
|
//Si sobreescribimos este método podremos tener en cuenta otras columnas para el calculo del importe total de un concepto
|
|
function CalcularImporteTotalConcepto(DataTable: TDADataTable): Double; override;
|
|
procedure ValidarCampos(DataTable: TDADataTable); override;
|
|
procedure DesglosarPorteDetalles(ImportePorte: Currency; ADetalles: IDAStronglyTypedDataTable);
|
|
function DarTotalPorteTotal(ADetalles: IDAStronglyTypedDataTable): Double;
|
|
|
|
public
|
|
procedure AnadirArticulos(ADetalles: IDAStronglyTypedDataTable; ACliente: IBizCliente; const ANuevaFila :Boolean = True); reintroduce; overload;
|
|
procedure ActualizarDetalles(ADetalles: IDAStronglyTypedDataTable; ACliente: IBizCliente); overload;
|
|
constructor Create; override;
|
|
destructor Destroy; override;
|
|
end;
|
|
|
|
implementation
|
|
|
|
uses Dialogs, uDialogUtils, Variants, uControllerDetallesBase, uDataModulePresupuestosCliente, uArticulosPresupuestoClienteController,
|
|
uDataTableUtils, uCalculosUtils;
|
|
|
|
{ TDetallesPresupuestoClienteController }
|
|
|
|
procedure TDetallesPresupuestoClienteController.ActualizarDetalles(ADetalles: IDAStronglyTypedDataTable; ACliente: IBizCliente);
|
|
var
|
|
AArticulos : IBizArticulo;
|
|
begin
|
|
if Assigned(ADetalles) then
|
|
begin
|
|
try
|
|
AArticulos := (FArticulosController.BuscarTodos(ACliente) as IBizArticulo);
|
|
ActualizarDetalles(ADetalles, AArticulos);
|
|
ShowInfoMessage('Se ha actualizado el descuento para el cliente seleccionado');
|
|
finally
|
|
AArticulos := Nil;
|
|
end;
|
|
end;
|
|
end;
|
|
|
|
procedure TDetallesPresupuestoClienteController.AnadirArticulos(ADetalles: IDAStronglyTypedDataTable; ACliente: IBizCliente; const ANuevaFila :Boolean);
|
|
var
|
|
AArticulos: IBizArticulo;
|
|
begin
|
|
if Assigned(ADetalles) then
|
|
begin
|
|
try
|
|
AArticulos := (FArticulosController.BuscarTodos(ACliente) as IBizArticulo);
|
|
|
|
//Si nueva fila es false, quiere decir que se sustituye un determinado artículo, por ello la lista a seleccionar no debe ser multiselect
|
|
if ANuevaFila then
|
|
begin
|
|
AArticulos := (FArticulosController as IArticulosPresupuestoClienteController).ElegirArticulos(AArticulos, 'Elija los artículos que desea añadir a este presupuesto de cliente', True);
|
|
Add(ADetalles, AArticulos)
|
|
end
|
|
else
|
|
begin
|
|
AArticulos := (FArticulosController as IArticulosPresupuestoClienteController).ElegirArticulos(AArticulos, 'Elija el artículo que desea añadir a este presupuesto de cliente', False);
|
|
RellenarDetalle(ADetalles, AArticulos);
|
|
end;
|
|
|
|
finally
|
|
AArticulos := Nil;
|
|
end;
|
|
end;
|
|
end;
|
|
|
|
procedure TDetallesPresupuestoClienteController.AsignarController;
|
|
begin
|
|
FArticulosController := TArticulosPresupuestoClienteController.Create;
|
|
end;
|
|
|
|
{
|
|
procedure TDetallesPresupuestoClienteController.AsignarDatos(ADetalles: IDAStronglyTypedDataTable; IDCabecera: Integer);
|
|
begin
|
|
inherited;
|
|
|
|
with (ADetalles as IBizDetallesPresupuestoCliente) do
|
|
begin
|
|
Edit;
|
|
ID := FDataModule.GetNextID(DataTable.LogicalName);
|
|
ID_PEDIDO := IDCabecera;
|
|
Post
|
|
end;
|
|
end;
|
|
}
|
|
|
|
function TDetallesPresupuestoClienteController.CalcularImporteTotalConcepto(DataTable: TDADataTable): Double;
|
|
begin
|
|
Result := CalcularLineaConcepto(DataTable);
|
|
end;
|
|
|
|
constructor TDetallesPresupuestoClienteController.Create;
|
|
begin
|
|
inherited;
|
|
FDataModule := TDataModulePresupuestosCliente.Create(Nil);
|
|
end;
|
|
|
|
function TDetallesPresupuestoClienteController.DarTotalPorteTotal(ADetalles: IDAStronglyTypedDataTable): Double;
|
|
begin
|
|
Result := DarTotalPorte(ADetalles);
|
|
end;
|
|
|
|
procedure TDetallesPresupuestoClienteController.DesglosarPorteDetalles(ImportePorte: Currency; ADetalles: IDAStronglyTypedDataTable);
|
|
begin
|
|
DesglosarPorte(ImportePorte, ADetalles);
|
|
ActualizarTotales(ADetalles);
|
|
end;
|
|
|
|
destructor TDetallesPresupuestoClienteController.Destroy;
|
|
begin
|
|
FDataModule := Nil;
|
|
inherited;
|
|
end;
|
|
|
|
|
|
procedure TDetallesPresupuestoClienteController.RellenarOtros(ADetalles: IDAStronglyTypedDataTable; AArticulos: IBizArticulo);
|
|
begin
|
|
//En Tecsitel no se tiene en cuenta el descuento de cliente para el precio PVP
|
|
// if Assigned(AArticulos) then
|
|
// ADetalles.DataTable.FieldByName(CAMPO_DESCUENTO).AsFloat := AArticulos.DESCUENTO
|
|
// else
|
|
// ADetalles.DataTable.FieldByName(CAMPO_DESCUENTO).AsFloat := 0;
|
|
end;
|
|
|
|
procedure TDetallesPresupuestoClienteController.ValidarCampos(DataTable: TDADataTable);
|
|
begin
|
|
inherited;
|
|
ValidarCamposLineaConcepto(DataTable);
|
|
end;
|
|
|
|
procedure TDetallesPresupuestoClienteController.RellenarImportes(ADetalles: IDAStronglyTypedDataTable; AArticulos: IBizArticulo);
|
|
begin
|
|
//Como en tecsitel no hay descuento por linea de detalle, solo recuperamos nuevamente el valor del articulo cuando el detalle no tenga niguno
|
|
//de esta forma evitamos que al cambiar de cliente se quiten los importes que se hubiesen establecido para los articulos.
|
|
if ADetalles.DataTable.FieldByName(CAMPO_IMPORTE_UNIDAD).IsNull then
|
|
if Assigned(AArticulos) then
|
|
ADetalles.DataTable.FieldByName(CAMPO_IMPORTE_UNIDAD).AsVariant := AArticulos.PRECIO_PVP_TOTAL
|
|
else
|
|
ADetalles.DataTable.FieldByName(CAMPO_IMPORTE_UNIDAD).AsVariant := Null;
|
|
end;
|
|
|
|
end.
|