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.
LuisLeon_FactuGES2/Source/Modulos/Pedidos de cliente/Controller/uDetallesPedidoClienteController.pas

167 lines
6.6 KiB
ObjectPascal

unit uDetallesPedidoClienteController;
interface
uses
uDADataTable, uControllerDetallesArticulos, uBizDetallesPedidoCliente, uIDataModulePedidosCliente,
uBizArticulos, uBizContactos;
const
CAMPO_REFERENCIA_FABRICANTE = 'REFERENCIA_FABRICANTE';
type
IDetallesPedidoClienteController = interface(IControllerDetallesArticulos)
['{FD68EA89-E41E-4962-ACFB-D9D801F6EC1A}']
procedure AnadirArticulos(ADetalles: IDAStronglyTypedDataTable; ACliente: IBizCliente; const ANuevaFila :Boolean = True; const ACantidad: Integer = 1); overload;
procedure ActualizarDetalles(ADetalles: IDAStronglyTypedDataTable; ACliente: IBizCliente); overload;
// function ArticulosPendientes(const ID : Integer): IBizDetallesPedidoClientePend;
procedure DesglosarPorteDetalles(ImportePorte: Currency; ADetalles: IDAStronglyTypedDataTable);
function DarTotalPorteTotal(ADetalles: IDAStronglyTypedDataTable): Double;
end;
TDetallesPedidoClienteController = class(TControllerDetallesArticulos, IDetallesPedidoClienteController)
private
FDataModule : IDataModulePedidosCliente;
protected
procedure RellenarOtros(ADetalles: IDAStronglyTypedDataTable; AArticulos: IBizArticulo); 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;
// function ArticulosPendientes(const ID : Integer): IBizDetallesPedidoClientePend;
constructor Create; override;
destructor Destroy; override;
end;
implementation
uses uDAInterfaces, Variants, uControllerDetallesBase, uDataModulePedidosCliente, uDialogUtils,
uCalculosUtils, schArticulosClient_Intf, schPedidosClienteClient_Intf, uArticulosPedidoClienteController;
{ 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; const ACantidad: Integer);
var
AArticulos: IBizArticulo;
begin
if Assigned(ADetalles) then
begin
try
// AArticulos := (FArticulosController.BuscarTodosPorCliente as IBizArticulo);
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 pedido a proveedor', True, ACliente);
Add(ADetalles, AArticulos, ACantidad)
end
else
begin
AArticulos := (FArticulosController as IArticulosPedidoClienteController).ElegirArticulos(AArticulos, 'Elija el artículo que desea añadir a este pedido a proveedor', False, ACliente);
RellenarDetalle(ADetalles, AArticulos, ACantidad);
end;
finally
AArticulos := Nil;
end;
end;
end;
{function TDetallesPedidoClienteController.ArticulosPendientes(const ID: Integer): IBizDetallesPedidoClientePend;
begin
Result := FDataModule.GetArticulosPendientes(ID);
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.RellenarOtros(ADetalles: IDAStronglyTypedDataTable; AArticulos: IBizArticulo);
var
AField: TDAField;
begin
if Assigned(AArticulos) then
ADetalles.DataTable.FieldByName(CAMPO_DESCUENTO).AsFloat := AArticulos.DESCUENTO
else
ADetalles.DataTable.FieldByName(CAMPO_DESCUENTO).AsFloat := 0;
//Sobreescribimos el id del articulo por el campo ID_ARTICULO que nos hemos tenido que crear para
//almacenar el codigo de artículo ya que ID esta destinado a ID_ARTICULO||ID_PROVEEDOR, para identificar de forma
//unica los articulos desglosados por proveedor.
AField := AArticulos.DataTable.FindField(CAMPO_ID_ARTICULOS);
if Assigned(AField) then
ADetalles.DataTable.FieldByName(CAMPO_ID_ARTICULOS).AsVariant := AField.AsVariant;
end;
procedure TDetallesPedidoClienteController.ValidarCampos(DataTable: TDADataTable);
begin
inherited;
ValidarCamposLineaConcepto(DataTable);
end;
procedure TDetallesPedidoClienteController.RellenarImportes(ADetalles: IDAStronglyTypedDataTable; AArticulos: IBizArticulo);
begin
if Assigned(AArticulos) then
ADetalles.DataTable.FieldByName(CAMPO_IMPORTE_UNIDAD).AsVariant := AArticulos.PRECIO_COSTE
else
ADetalles.DataTable.FieldByName(CAMPO_IMPORTE_UNIDAD).AsVariant := Null;
end;
end.