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); overload; procedure ActualizarDetalles(ADetalles: IDAStronglyTypedDataTable; ACliente: IBizCliente); overload; procedure DesglosarPorteDetalles(ImportePorte: Currency; ADetalles: IDAStronglyTypedDataTable); function DarTotalPorteTotal(ADetalles: IDAStronglyTypedDataTable): Double; end; TDetallesPedidoClienteController = class(TControllerDetallesArticulos, IDetallesPedidoClienteController) private FDataModule : IDataModulePedidosCliente; 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, 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); 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) 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); end; finally AArticulos := Nil; end; end; end; procedure TDetallesPedidoClienteController.AsignarController; begin FArticulosController := TArticulosPedidoClienteController.Create; end; procedure TDetallesPedidoClienteController.AsignarDatos(ADetalles: IDAStronglyTypedDataTable; IDCabecera: Integer); begin inherited; with (ADetalles as IBizDetallesPedidoCliente) do begin Edit; ID := FDataModule.GetNextID(DataTable.LogicalName); ID_PEDIDO := IDCabecera; Post end; 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); begin if Assigned(AArticulos) then ADetalles.DataTable.FieldByName(CAMPO_DESCUENTO).AsFloat := AArticulos.DESCUENTO else ADetalles.DataTable.FieldByName(CAMPO_DESCUENTO).AsFloat := 0; 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.