This repository has been archived on 2024-11-28. You can view files and clone it, but cannot push or open issues or pull requests.
Noviseda_FactuGES2/Source/Modulos/Pedidos de cliente/Controller/uDetallesPedidoClienteController.pas
2010-03-04 19:11:24 +00:00

183 lines
7.2 KiB
ObjectPascal

unit uDetallesPedidoClienteController;
interface
uses
uDADataTable, uControllerDetallesArticulos, uBizDetallesPedidoCliente, uIDataModulePedidosCliente,
uBizArticulos, uBizContactos;
type
IDetallesPedidoClienteController = interface(IControllerDetallesArticulos)
['{8D1D3559-E695-4962-9999-404B26B50D6C}']
procedure AnadirArticulos(ADetalles: IDAStronglyTypedDataTable; ACliente: IBizCliente; const ANuevaFila :Boolean = True; const ACantidad: Integer = 1); overload;
procedure ActualizarDetalles(ADetalles: IDAStronglyTypedDataTable; ACliente: IBizCliente); overload;
procedure DesglosarPorteDetalles(ImportePorte: Currency; ADetalles: IDAStronglyTypedDataTable);
function DarTotalPorteTotal(ADetalles: IDAStronglyTypedDataTable): Double;
procedure ModificarCantidadColores(ADetalles: IDAStronglyTypedDataTable);
end;
TDetallesPedidoClienteController = class(TControllerDetallesArticulos, IDetallesPedidoClienteController)
private
FDataModule : IDataModulePedidosCliente;
protected
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; const ACantidad: Integer = 1); overload;
procedure ActualizarDetalles(ADetalles: IDAStronglyTypedDataTable; ACliente: IBizCliente); overload;
procedure ModificarCantidadColores(ADetalles: IDAStronglyTypedDataTable);
constructor Create; override;
destructor Destroy; override;
end;
implementation
uses Dialogs, Controls, uDialogUtils, Variants, uControllerDetallesBase, uEditorColores,
uDataModulePedidosCliente, uArticulosPedidoClienteController, uDataTableUtils, uCalculosUtils;
{ TDetallesPedidoClienteController }
procedure TDetallesPedidoClienteController.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 han actualizado los descuentos para el cliente seleccionado');
finally
AArticulos := Nil;
end;
end;
end;
procedure TDetallesPedidoClienteController.AnadirArticulos(ADetalles: IDAStronglyTypedDataTable; ACliente: IBizCliente; const ANuevaFila :Boolean = True; const ACantidad: Integer = 1);
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 IArticulosPedidoClienteController).ElegirArticulos(AArticulos, 'Elija los artículos que desea añadir a este presupuesto de cliente', True);
Add(ADetalles, AArticulos, ACantidad)
end
else
begin
AArticulos := (FArticulosController as IArticulosPedidoClienteController).ElegirArticulos(AArticulos, 'Elija el artículo que desea añadir a este presupuesto de cliente', False);
RellenarDetalle(ADetalles, AArticulos, ACantidad);
end;
finally
AArticulos := Nil;
end;
end;
end;
procedure TDetallesPedidoClienteController.AsignarController;
begin
FArticulosController := TArticulosPedidoClienteController.Create;
end;
function TDetallesPedidoClienteController.CalcularImporteTotalConcepto(DataTable: TDADataTable): Double;
begin
Result := CalcularLineaConcepto(DataTable);
end;
constructor TDetallesPedidoClienteController.Create;
begin
inherited;
FDataModule := TDataModulePedidosCliente.Create(Nil);
end;
function TDetallesPedidoClienteController.DarTotalPorteTotal(ADetalles: IDAStronglyTypedDataTable): Double;
begin
Result := DarTotalPorte(ADetalles);
end;
procedure TDetallesPedidoClienteController.DesglosarPorteDetalles(ImportePorte: Currency; ADetalles: IDAStronglyTypedDataTable);
begin
DesglosarPorte(ImportePorte, ADetalles);
ActualizarTotales(ADetalles);
end;
destructor TDetallesPedidoClienteController.Destroy;
begin
FDataModule := Nil;
inherited;
end;
procedure TDetallesPedidoClienteController.ModificarCantidadColores(ADetalles: IDAStronglyTypedDataTable);
var
ADetallesAux: IBizDetallesPedidoCliente;
begin
if Assigned(ADetalles) then
begin
ADetallesAux := (ADetalles as IBizDetallesPedidoCliente);
with TfEditorColores.Create(NIL) do
try
dsDataTable.DataTable := ADetallesAux.DetalleColores.DataTable;
Referencia := ADetallesAux.REFERENCIA;
Descripcion := ADetallesAux.CONCEPTO;
if (ShowModal = mrOK) then
begin
if ADetallesAux.DetalleColores.DataTable.Editing then
ADetallesAux.DetalleColores.DataTable.Post;
if not ADetallesAux.DataTable.Editing then
ADetallesAux.DataTable.Edit;
ADetallesAux.CANTIDAD := Total;
if ADetallesAux.DataTable.Editing then
ADetallesAux.DataTable.post;
ActualizarTotales(ADetalles);
end
else
ADetallesAux.DetalleColores.DataTable.Cancel;
finally
Release;
end;
end;
end;
procedure TDetallesPedidoClienteController.RellenarOtros(ADetalles: IDAStronglyTypedDataTable; AArticulos: IBizArticulo);
begin
//Solo para albaranes que es donde se distingue entre colores para tema de stock
if Assigned(AArticulos) then
ModificarCantidadColores(ADetalles);
end;
procedure TDetallesPedidoClienteController.ValidarCampos(DataTable: TDADataTable);
begin
inherited;
ValidarCamposLineaConcepto(DataTable);
end;
procedure TDetallesPedidoClienteController.RellenarImportes(ADetalles: IDAStronglyTypedDataTable; AArticulos: IBizArticulo);
begin
//Como en noviseda 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
else
ADetalles.DataTable.FieldByName(CAMPO_IMPORTE_UNIDAD).AsVariant := Null;
end;
end.