unit uDetallesAlbaranClienteController; interface uses uDADataTable, uControllerDetallesArticulos, uBizDetallesAlbaranCliente, uIDataModuleAlbaranesCliente, uBizArticulos, uBizContactos; type IDetallesAlbaranClienteController = interface(IControllerDetallesArticulos) ['{6AD99D47-2856-47B1-9620-DD115726B0E1}'] 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; TDetallesAlbaranClienteController = class(TControllerDetallesArticulos, IDetallesAlbaranClienteController) private FDataModule : IDataModuleAlbaranesCliente; protected // procedure AsignarDatos(ADetalles: IDAStronglyTypedDataTable; IDCabecera: Integer); override; 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; procedure ModificarCantidadColores(ADetalles: IDAStronglyTypedDataTable); constructor Create; override; destructor Destroy; override; end; implementation uses Controls, Dialogs, uDialogUtils, Variants, uControllerDetallesBase, uEditorColores, uCalculosUtils, uDataModuleAlbaranesCliente, uArticulosAlbaranClienteController; { TDetallesAlbaranClienteController } procedure TDetallesAlbaranClienteController.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'); Esta desactivado el descuento general para los albaranes de cliente finally AArticulos := Nil; end; end; end; procedure TDetallesAlbaranClienteController.AnadirArticulos(ADetalles: IDAStronglyTypedDataTable; ACliente: IBizCliente; const ANuevaFila :Boolean; const ACantidad: Integer); 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 IArticulosAlbaranClienteController).ElegirArticulos(AArticulos, 'Elija los artículos que desea añadir a este albarán de cliente', True); Add(ADetalles, AArticulos, ACantidad) end else begin AArticulos := (FArticulosController as IArticulosAlbaranClienteController).ElegirArticulos(AArticulos, 'Elija el artículo que desea añadir a este albarán de cliente', False); RellenarDetalle(ADetalles, AArticulos, ACantidad); end; finally AArticulos := Nil; end; end; end; procedure TDetallesAlbaranClienteController.AsignarController; begin FArticulosController := TArticulosAlbaranClienteController.Create; end; {procedure TDetallesAlbaranClienteController.AsignarDatos(ADetalles: IDAStronglyTypedDataTable; IDCabecera: Integer); begin inherited; with (ADetalles as IBizDetallesAlbaranCliente) do begin Edit; // ID := FDataModule.GetNextID(DataTable.LogicalName); ID_ALBARAN := IDCabecera; Post end; end;} function TDetallesAlbaranClienteController.CalcularImporteTotalConcepto(DataTable: TDADataTable): Double; begin Result := CalcularLineaConcepto(DataTable); end; constructor TDetallesAlbaranClienteController.Create; begin inherited; FDataModule := TDataModuleAlbaranesCliente.Create(Nil); end; function TDetallesAlbaranClienteController.DarTotalPorteTotal(ADetalles: IDAStronglyTypedDataTable): Double; begin Result := DarTotalPorte(ADetalles); end; procedure TDetallesAlbaranClienteController.DesglosarPorteDetalles(ImportePorte: Currency; ADetalles: IDAStronglyTypedDataTable); begin DesglosarPorte(ImportePorte, ADetalles); ActualizarTotales(ADetalles); end; destructor TDetallesAlbaranClienteController.Destroy; begin FDataModule := Nil; inherited; end; procedure TDetallesAlbaranClienteController.ModificarCantidadColores(ADetalles: IDAStronglyTypedDataTable); var ADetallesAux: IBizDetallesAlbaranCliente; begin if Assigned(ADetalles) then begin ADetallesAux := (ADetalles as IBizDEtallesAlbaranCliente); with TfrEditorColores.Create(NIL) do begin dsDataTable.DataTable := ADetallesAux.DetalleColores.DataTable; if (showModal = mrOK) then begin ADetallesAux.DetalleColores.DataTable.Post; ADetallesAux.DataTable.Edit; ADetallesAux.CANTIDAD := GetTotal; ADetallesAux.DataTable.post; ActualizarTotales(ADetalles); end else ADetallesAux.DetalleColores.DataTable.Cancel; Free; end; end; end; procedure TDetallesAlbaranClienteController.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 TDetallesAlbaranClienteController.ValidarCampos(DataTable: TDADataTable); begin inherited; ValidarCamposLineaConcepto(DataTable); end; procedure TDetallesAlbaranClienteController.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 else ADetalles.DataTable.FieldByName(CAMPO_IMPORTE_UNIDAD).AsVariant := Null; end; end.