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); function ArticulosPendientes(const ID : Integer): IBizPedidoClienteArticulosPend; function ArtColoresPendientes(const ID : Integer): IBizPedidoClienteArtColoresPend; 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); function ArticulosPendientes(const ID : Integer): IBizPedidoClienteArticulosPend; function ArtColoresPendientes(const ID : Integer): IBizPedidoClienteArtColoresPend; constructor Create; override; destructor Destroy; override; end; implementation uses Dialogs, cxControls, uDAInterfaces, Controls, uDialogUtils, Variants, uControllerDetallesBase, uEditorColores, uDataModulePedidosCliente, uArticulosPedidoClienteController, uDataTableUtils, uCalculosUtils, schPedidosClienteClient_Intf; { 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; function TDetallesPedidoClienteController.ArtColoresPendientes(const ID: Integer): IBizPedidoClienteArtColoresPend; var Condicion: TDAWhereExpression; begin ShowHourglassCursor; try Result := FDataModule.GetArtColoresPendientes; with Result.DataTable.DynamicWhere do begin // (ID_PEDIDO >= ID) Condicion := NewBinaryExpression(NewField('', fld_PedidoCliente_Art_Colores_PendientesID_PEDIDO), NewConstant(ID, datInteger), dboEqual); if IsEmpty then Expression := Condicion else Expression := NewBinaryExpression(Expression, Condicion, dboAnd); end; finally HideHourglassCursor; end; end; function TDetallesPedidoClienteController.ArticulosPendientes( const ID: Integer): IBizPedidoClienteArticulosPend; 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.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.