2011-11-14 17:40:41 +00:00
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 ;
2022-03-15 16:08:43 +00:00
procedure SetPrecioPunto ( const AValue: Currency ) ;
function GetPrecioPunto: Currency ;
property PrecioPunto : Currency read GetPrecioPunto write SetPrecioPunto;
2011-11-14 17:40:41 +00:00
end ;
TDetallesAlbaranClienteController = class( TControllerDetallesArticulos, IDetallesAlbaranClienteController)
private
FDataModule : IDataModuleAlbaranesCliente;
2022-03-15 16:08:43 +00:00
FPrecioPunto: Currency ;
2011-11-14 17:40:41 +00:00
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 ;
2022-03-15 16:08:43 +00:00
function GetPrecioPunto: Currency ;
procedure SetPrecioPunto( const Value: Currency ) ;
2011-11-14 17:40:41 +00:00
public
procedure AnadirArticulos( ADetalles: IDAStronglyTypedDataTable; ACliente: IBizCliente; const ANuevaFila : Boolean = True ; const ACantidad: Integer = 1 ) ; overload ;
procedure ActualizarDetalles( ADetalles: IDAStronglyTypedDataTable; ACliente: IBizCliente) ; overload ;
constructor Create; override ;
destructor Destroy; override ;
2022-03-15 16:08:43 +00:00
property PrecioPunto : Currency read GetPrecioPunto write SetPrecioPunto;
2011-11-14 17:40:41 +00:00
end ;
implementation
2015-05-04 15:46:17 +00:00
uses Dialogs, uDialogUtils, Variants, uControllerDetallesBase, uFactuGES_App, uNumUtils,
2011-11-14 17:40:41 +00:00
uCalculosUtils, uDataModuleAlbaranesCliente, uArticulosAlbaranClienteController;
{ TDetallesAlbaranClienteController }
procedure TDetallesAlbaranClienteController. ActualizarDetalles( ADetalles: IDAStronglyTypedDataTable; ACliente: IBizCliente) ;
var
AArticulos : IBizArticulo;
begin
if Assigned( ADetalles) then
begin
try
2013-04-26 12:34:42 +00:00
// AArticulos := (FArticulosController.BuscarTodos(ACliente) as IBizArticulo);
// ActualizarDetalles(ADetalles, AArticulos);
ActualizarDetalles( ADetalles, ACliente. DESCUENTO_LINEA) ;
ShowInfoMessage( 'Se han actualizado los descuentos para el cliente seleccionado' ) ;
2011-11-14 17:40:41 +00:00
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<72> culo, por ello la lista a seleccionar no debe ser multiselect
if ANuevaFila then
begin
AArticulos : = ( FArticulosController as IArticulosAlbaranClienteController) . ElegirArticulos( AArticulos, 'Elija los art<72> culos que desea a<> adir a este albar<61> n de cliente' , True ) ;
Add( ADetalles, AArticulos, ACantidad)
end
else
begin
AArticulos : = ( FArticulosController as IArticulosAlbaranClienteController) . ElegirArticulos( AArticulos, 'Elija el art<72> culo que desea a<> adir a este albar<61> 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 ) ;
2022-03-15 16:08:43 +00:00
FPrecioPunto: = AppFactuGES. EmpresaActiva. PRECIO_PUNTO;
2011-11-14 17:40:41 +00:00
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 ;
2022-03-15 16:08:43 +00:00
function TDetallesAlbaranClienteController. GetPrecioPunto: Currency ;
begin
Result : = FPrecioPunto;
end ;
2011-11-14 17:40:41 +00:00
procedure TDetallesAlbaranClienteController. RellenarOtros( ADetalles: IDAStronglyTypedDataTable; AArticulos: IBizArticulo) ;
2013-04-26 12:34:42 +00:00
var
ACadena : String ;
2011-11-14 17:40:41 +00:00
begin
2013-04-26 12:34:42 +00:00
ACadena : = ADetalles. DataTable. FieldByName( 'CONCEPTO' ) . AsString;
if ( AArticulos. REFERENCIA_PROV < > '' ) then
ACadena : = AArticulos. REFERENCIA_PROV + ' ' + ACadena;
if ( AArticulos. FAMILIA < > '' ) then
ACadena : = AArticulos. FAMILIA + ' ' + ACadena;
ADetalles. DataTable. FieldByName( 'CONCEPTO' ) . AsString : = ACadena;
//El descuento que hemos puesto a la vista de articulos es el del cliente seleccionado en el documento
2011-11-14 17:40:41 +00:00
if Assigned( AArticulos) then
ADetalles. DataTable. FieldByName( CAMPO_DESCUENTO) . AsFloat : = AArticulos. DESCUENTO
else
ADetalles. DataTable. FieldByName( CAMPO_DESCUENTO) . AsFloat : = 0 ;
end ;
2022-03-15 16:08:43 +00:00
procedure TDetallesAlbaranClienteController. SetPrecioPunto( const Value: Currency ) ;
begin
FPrecioPunto : = Value;
FArticulosController. PrecioPunto : = FPrecioPunto;
end ;
2011-11-14 17:40:41 +00:00
procedure TDetallesAlbaranClienteController. ValidarCampos( DataTable: TDADataTable) ;
begin
inherited ;
ValidarCamposLineaConcepto( DataTable) ;
end ;
procedure TDetallesAlbaranClienteController. RellenarImportes( ADetalles: IDAStronglyTypedDataTable; AArticulos: IBizArticulo) ;
begin
2013-04-26 12:34:42 +00:00
if ADetalles. DataTable. FieldByName( CAMPO_IMPORTE_UNIDAD) . IsNull then
2011-11-14 17:40:41 +00:00
if Assigned( AArticulos) then
2022-03-15 16:08:43 +00:00
ADetalles. DataTable. FieldByName( CAMPO_IMPORTE_UNIDAD) . AsVariant : = RoundCurrency( AArticulos. PRECIO_COSTE * FPrecioPunto)
2011-11-14 17:40:41 +00:00
else
ADetalles. DataTable. FieldByName( CAMPO_IMPORTE_UNIDAD) . AsVariant : = Null;
end ;
end .