2007-11-05 18:00:22 +00:00
unit uDetallesFacturaClienteController;
interface
uses
2008-09-17 18:38:38 +00:00
Classes, uDADataTable, uControllerDetallesArticulos, uBizDetallesFacturaCliente, uIDataModuleFacturasCliente,
2007-11-05 18:00:22 +00:00
uBizContactos, uBizArticulos;
type
IDetallesFacturaClienteController = interface( IControllerDetallesArticulos)
[ '{D3942A48-C55B-4A98-AC5B-B5E652ED393E}' ]
2008-02-06 18:02:35 +00:00
procedure AnadirArticulos( ADetalles: IDAStronglyTypedDataTable; ACliente: IBizCliente; const ANuevaFila : Boolean = True ; const ACantidad: Integer = 1 ) ; overload ;
2007-11-05 18:00:22 +00:00
procedure ActualizarDetalles( ADetalles: IDAStronglyTypedDataTable; ACliente: IBizCliente) ;
procedure AnadirDetalleFacturaAsociadaAbono( ADetalles: IBizDetallesFacturaCliente; AReferencia: String ; AFecha: String ) ;
procedure DesglosarPorteDetalles( ImportePorte: Currency ; ADetalles: IDAStronglyTypedDataTable) ;
function DarTotalPorteTotal( ADetalles: IDAStronglyTypedDataTable) : Double ;
end ;
TDetallesFacturaClienteController = class( TControllerDetallesArticulos, IDetallesFacturaClienteController)
private
FDataModule : IDataModuleFacturasCliente;
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
2008-09-17 18:38:38 +00:00
function DarListaTiposDetalle: TStringList; override ;
2008-02-06 18:02:35 +00:00
procedure AnadirArticulos( ADetalles: IDAStronglyTypedDataTable; ACliente: IBizCliente; const ANuevaFila : Boolean = True ; const ACantidad: Integer = 1 ) ; overload ;
2007-11-05 18:00:22 +00:00
procedure ActualizarDetalles( ADetalles: IDAStronglyTypedDataTable; ACliente: IBizCliente) ; overload ;
//ABONOS
procedure AnadirDetalleFacturaAsociadaAbono( ADetalles: IBizDetallesFacturaCliente; AReferencia: String ; AFecha: String ) ;
constructor Create; override ;
destructor Destroy; override ;
end ;
implementation
{ TDetallesFacturaClienteController }
uses Variants, uDataModuleFacturasCliente, uArticulosFacturaClienteController,
uControllerDetallesBase, Dialogs, uDialogUtils, SysUtils, uCalculosUtils;
procedure TDetallesFacturaClienteController. ActualizarDetalles( ADetalles: IDAStronglyTypedDataTable; ACliente: IBizCliente) ;
var
AArticulos : IBizArticulo;
begin
if Assigned( ADetalles) then
begin
try
AArticulos : = ( FArticulosController. BuscarTodos( ACliente) as IBizArticulo) ;
ActualizarDetalles( ADetalles, AArticulos) ;
2008-08-20 10:18:16 +00:00
ShowInfoMessage( 'Se ha actualizado el descuento para el cliente seleccionado' ) ;
2007-11-05 18:00:22 +00:00
finally
AArticulos : = Nil ;
end ;
end ;
end ;
2008-02-06 18:02:35 +00:00
procedure TDetallesFacturaClienteController. AnadirArticulos( ADetalles: IDAStronglyTypedDataTable; ACliente: IBizCliente; const ANuevaFila : Boolean ; const ACantidad: Integer ) ;
2007-11-05 18:00:22 +00:00
var
AArticulos: IBizArticulo;
begin
if Assigned( ADetalles) then
begin
try
2008-02-05 20:38:38 +00:00
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 IArticulosFacturaClienteController) . ElegirArticulos( AArticulos, 'Elija los art<72> culos que desea a<> adir a esta factura de cliente' , True ) ;
2008-02-06 18:02:35 +00:00
Add( ADetalles, AArticulos, ACantidad)
2008-02-05 20:38:38 +00:00
end
else
begin
AArticulos : = ( FArticulosController as IArticulosFacturaClienteController) . ElegirArticulos( AArticulos, 'Elija el art<72> culo que desea a<> adir a esta factura de cliente' , False ) ;
2008-02-06 18:02:35 +00:00
RellenarDetalle( ADetalles, AArticulos, ACantidad) ;
2008-02-05 20:38:38 +00:00
end ;
2007-11-05 18:00:22 +00:00
finally
AArticulos : = Nil ;
end ;
end ;
end ;
procedure TDetallesFacturaClienteController. AnadirDetalleFacturaAsociadaAbono( ADetalles: IBizDetallesFacturaCliente; AReferencia: String ; AFecha: String ) ;
begin
AnadirConceptoInicial( ADetalles, 'ABONO DE FACTURA ' + AReferencia + ' con fecha ' + AFecha) ;
end ;
procedure TDetallesFacturaClienteController. AsignarController;
begin
FArticulosController : = TArticulosFacturaClienteController. Create;
end ;
{ procedure TDetallesFacturaClienteController. AsignarDatos( ADetalles: IDAStronglyTypedDataTable; IDCabecera: Integer ) ;
begin
inherited ;
with ( ADetalles as IBizDetallesFacturaCliente) do
begin
Edit;
// ID := FDataModule.GetNextID(DataTable.LogicalName);
ID_FACTURA : = IDCabecera;
Post
end ;
end ; }
function TDetallesFacturaClienteController. CalcularImporteTotalConcepto( DataTable: TDADataTable) : Double ;
begin
Result : = CalcularLineaConcepto( DataTable) ;
end ;
constructor TDetallesFacturaClienteController. Create;
begin
inherited ;
FDataModule : = TDataModuleFacturasCliente. Create( Nil ) ;
end ;
2008-09-17 18:38:38 +00:00
function TDetallesFacturaClienteController. DarListaTiposDetalle: TStringList;
begin
Result : = TStringList. Create;
Result . Values[ TIPO_DETALLE_CONCEPTO] : = TIPO_DETALLE_CONCEPTO;
Result . Values[ TIPO_DETALLE_TITULO] : = TIPO_DETALLE_TITULO;
// Result.Values[TIPO_DETALLE_TITULO_OPCIONAL] := TIPO_DETALLE_TITULO_OPCIONAL;
Result . Values[ TIPO_DETALLE_SUBTOTAL] : = TIPO_DETALLE_SUBTOTAL;
// Result.Values[TIPO_DETALLE_DESCUENTO] := TIPO_DETALLE_DESCUENTO;
// Result.Values[TIPO_DETALLE_SALTO] := TIPO_DETALLE_SALTO;
end ;
2007-11-05 18:00:22 +00:00
function TDetallesFacturaClienteController. DarTotalPorteTotal( ADetalles: IDAStronglyTypedDataTable) : Double ;
begin
Result : = DarTotalPorte( ADetalles) ;
end ;
procedure TDetallesFacturaClienteController. DesglosarPorteDetalles( ImportePorte: Currency ; ADetalles: IDAStronglyTypedDataTable) ;
begin
DesglosarPorte( ImportePorte, ADetalles) ;
ActualizarTotales( ADetalles) ;
end ;
destructor TDetallesFacturaClienteController. Destroy;
begin
FDataModule : = Nil ;
inherited ;
end ;
procedure TDetallesFacturaClienteController. RellenarOtros( ADetalles: IDAStronglyTypedDataTable; AArticulos: IBizArticulo) ;
begin
2008-06-11 10:42:33 +00:00
//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;
2007-11-05 18:00:22 +00:00
end ;
procedure TDetallesFacturaClienteController. ValidarCampos( DataTable: TDADataTable) ;
begin
inherited ;
ValidarCamposLineaConcepto( DataTable) ;
end ;
procedure TDetallesFacturaClienteController. RellenarImportes( ADetalles: IDAStronglyTypedDataTable; AArticulos: IBizArticulo) ;
begin
2008-08-20 10:18:16 +00:00
//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_PVP_TOTAL
else
ADetalles. DataTable. FieldByName( CAMPO_IMPORTE_UNIDAD) . AsVariant : = Null;
2007-11-05 18:00:22 +00:00
end ;
end .