2010-02-08 17:38:24 +00:00
unit uDetallesPresupuestoClienteController;
2007-10-26 18:19:55 +00:00
interface
uses
2009-03-27 10:57:28 +00:00
uDADataTable, uControllerDetallesBase, uControllerDetallesArticulos, uBizDetallesPresupuestoCliente, uIDataModulePresupuestosCliente,
2007-10-26 18:19:55 +00:00
uBizArticulos, uBizContactos;
type
IDetallesPresupuestoClienteController = interface( IControllerDetallesArticulos)
[ '{8D1D3559-E695-4962-9999-404B26B50D6C}' ]
2008-02-05 20:38:38 +00:00
procedure AnadirArticulos( ADetalles: IDAStronglyTypedDataTable; ACliente: IBizCliente; const ANuevaFila : Boolean = True ) ; overload ;
2007-10-26 18:19:55 +00:00
procedure ActualizarDetalles( ADetalles: IDAStronglyTypedDataTable; ACliente: IBizCliente) ; overload ;
procedure DesglosarPorteDetalles( ImportePorte: Currency ; ADetalles: IDAStronglyTypedDataTable) ;
function DarTotalPorteTotal( ADetalles: IDAStronglyTypedDataTable) : Double ;
2010-02-08 17:38:24 +00:00
function VariarPrecios( var APorcentaje: Variant ; var ATipoOperacion: Integer ) : Boolean ;
procedure AplicarAumento( ADataTable: IDAStronglyTypedDataTable; Posicion: TIntegerArray; APorcentaje: Variant ) ;
2007-10-26 18:19:55 +00:00
end ;
TDetallesPresupuestoClienteController = class( TControllerDetallesArticulos, IDetallesPresupuestoClienteController)
private
FDataModule : IDataModulePresupuestosCliente;
2009-03-27 10:57:28 +00:00
function CreateEditor( const AName : String ; const IID: TGUID; out Intf) : Boolean ;
2007-10-26 18:19:55 +00:00
protected
2007-11-05 17:49:11 +00:00
// procedure AsignarDatos(ADetalles: IDAStronglyTypedDataTable; IDCabecera: Integer); override;
2007-10-26 18:19:55 +00:00
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
2010-02-08 17:38:24 +00:00
function VariarPrecios( var APorcentaje: Variant ; var ATipoOperacion: Integer ) : Boolean ;
2008-02-05 20:38:38 +00:00
procedure AnadirArticulos( ADetalles: IDAStronglyTypedDataTable; ACliente: IBizCliente; const ANuevaFila : Boolean = True ) ; reintroduce ; overload ;
2007-10-26 18:19:55 +00:00
procedure ActualizarDetalles( ADetalles: IDAStronglyTypedDataTable; ACliente: IBizCliente) ; overload ;
2010-02-08 17:38:24 +00:00
procedure AplicarAumento( ADataTable: IDAStronglyTypedDataTable; Posicion: TIntegerArray; APorcentaje: Variant ) ;
2007-10-26 18:19:55 +00:00
constructor Create; override ;
destructor Destroy; override ;
end ;
implementation
2009-03-27 10:57:28 +00:00
uses Controls, SysUtils, Dialogs, uDAInterfaces, uDialogUtils, Variants, uDataModulePresupuestosCliente, uArticulosPresupuestoClienteController,
2010-02-08 17:38:24 +00:00
uDataTableUtils, uCalculosUtils, uIEditorVariarPrecios, uEditorRegistryUtils;
2007-10-26 18:19:55 +00:00
{ TDetallesPresupuestoClienteController }
procedure TDetallesPresupuestoClienteController. 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-10-26 18:19:55 +00:00
finally
AArticulos : = Nil ;
end ;
end ;
end ;
2008-02-05 20:38:38 +00:00
procedure TDetallesPresupuestoClienteController. AnadirArticulos( ADetalles: IDAStronglyTypedDataTable; ACliente: IBizCliente; const ANuevaFila : Boolean ) ;
2007-10-26 18:19:55 +00:00
var
AArticulos: IBizArticulo;
begin
if Assigned( ADetalles) then
begin
try
AArticulos : = ( FArticulosController. BuscarTodos( ACliente) as IBizArticulo) ;
2008-02-05 20:38:38 +00:00
//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 IArticulosPresupuestoClienteController) . ElegirArticulos( AArticulos, 'Elija los art<72> culos que desea a<> adir a este presupuesto de cliente' , True ) ;
Add( ADetalles, AArticulos)
end
else
begin
AArticulos : = ( FArticulosController as IArticulosPresupuestoClienteController) . ElegirArticulos( AArticulos, 'Elija el art<72> culo que desea a<> adir a este presupuesto de cliente' , False ) ;
RellenarDetalle( ADetalles, AArticulos) ;
end ;
2007-10-26 18:19:55 +00:00
finally
AArticulos : = Nil ;
end ;
end ;
end ;
2010-02-08 17:38:24 +00:00
procedure TDetallesPresupuestoClienteController. AplicarAumento( ADataTable: IDAStronglyTypedDataTable; Posicion: TIntegerArray;
APorcentaje: Variant ) ;
var
i: integer ;
AField: TDAField;
AsignarDtoPosicion: Integer ;
2007-10-26 18:19:55 +00:00
begin
2010-02-08 17:38:24 +00:00
if APorcentaje > 0 then
begin
AsignarDtoPosicion : = 0 ;
AField : = ADataTable. DataTable. FindField( CAMPO_POSICION) ;
if not Assigned( AField) then
raise Exception. Create( 'Campo ' + CAMPO_POSICION + ' no encontrado (AsignarDescuento)' ) ;
2007-10-26 18:19:55 +00:00
2010-02-08 17:38:24 +00:00
BeginUpdate( ADataTable) ;
try
with ADataTable do
begin
for i : = 0 to High( POSICION) do
begin
DataTable. First;
AsignarDtoPosicion : = POSICION[ i] ;
if DataTable. Locate( CAMPO_POSICION, AsignarDtoPosicion, [ ] ) then
begin
if ( DataTable. FieldByName( CAMPO_TIPO) . AsString = TIPO_DETALLE_CONCEPTO) then
begin
DataTable. Edit;
DataTable. FieldByName( CAMPO_IMPORTE_UNIDAD) . AsVariant : = ( DataTable. FieldByName( CAMPO_IMPORTE_UNIDAD) . AsVariant * ( APorcentaje/ 1 0 0 ) ) + DataTable. FieldByName( CAMPO_IMPORTE_UNIDAD) . AsVariant;
DataTable. Post;
end ;
end ;
end ;
Renumerar( DataTable, AsignarDtoPosicion) ;
end ;
finally
EndUpdate( ADataTable) ;
end ;
end ;
end ;
2009-03-27 10:57:28 +00:00
2010-02-08 17:38:24 +00:00
procedure TDetallesPresupuestoClienteController. AsignarController;
2009-03-27 10:57:28 +00:00
begin
2010-02-08 17:38:24 +00:00
FArticulosController : = TArticulosPresupuestoClienteController. Create;
2009-03-27 10:57:28 +00:00
end ;
2007-11-05 17:49:11 +00:00
{
2007-10-26 18:19:55 +00:00
procedure TDetallesPresupuestoClienteController. AsignarDatos( ADetalles: IDAStronglyTypedDataTable; IDCabecera: Integer ) ;
begin
inherited ;
with ( ADetalles as IBizDetallesPresupuestoCliente) do
begin
Edit;
ID : = FDataModule. GetNextID( DataTable. LogicalName) ;
ID_PEDIDO : = IDCabecera;
Post
end ;
end ;
2007-11-05 17:49:11 +00:00
}
2007-10-26 18:19:55 +00:00
function TDetallesPresupuestoClienteController. CalcularImporteTotalConcepto( DataTable: TDADataTable) : Double ;
begin
Result : = CalcularLineaConcepto( DataTable) ;
end ;
constructor TDetallesPresupuestoClienteController. Create;
begin
inherited ;
FDataModule : = TDataModulePresupuestosCliente. Create( Nil ) ;
end ;
2009-03-27 10:57:28 +00:00
function TDetallesPresupuestoClienteController. CreateEditor( const AName: String ; const IID: TGUID; out Intf) : Boolean ;
begin
Result : = Supports( EditorRegistry. CreateEditor( AName) , IID, Intf) ;
end ;
2007-10-26 18:19:55 +00:00
function TDetallesPresupuestoClienteController. DarTotalPorteTotal( ADetalles: IDAStronglyTypedDataTable) : Double ;
begin
Result : = DarTotalPorte( ADetalles) ;
end ;
procedure TDetallesPresupuestoClienteController. DesglosarPorteDetalles( ImportePorte: Currency ; ADetalles: IDAStronglyTypedDataTable) ;
begin
DesglosarPorte( ImportePorte, ADetalles) ;
2009-03-27 10:57:28 +00:00
ActualizarTotales( ADetalles) ;
2007-10-26 18:19:55 +00:00
end ;
destructor TDetallesPresupuestoClienteController. Destroy;
begin
FDataModule : = Nil ;
inherited ;
end ;
procedure TDetallesPresupuestoClienteController. 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-10-26 18:19:55 +00:00
end ;
procedure TDetallesPresupuestoClienteController. ValidarCampos( DataTable: TDADataTable) ;
begin
inherited ;
ValidarCamposLineaConcepto( DataTable) ;
end ;
2010-02-08 17:38:24 +00:00
function TDetallesPresupuestoClienteController. VariarPrecios( var APorcentaje: Variant ; var ATipoOperacion: Integer ) : Boolean ;
var
AEditor: IEditorVariarPrecios;
begin
Result : = False ;
CreateEditor( 'EditorVariarPrecios' , IEditorVariarPrecios, AEditor) ;
if Assigned( AEditor) then
try
if ( AEditor. ShowModal = mrOk) then
begin
APorcentaje : = AEditor. Porcentaje;
ATipoOperacion : = AEditor. TipoOperacion;
Result : = True ;
end ;
finally
AEditor. Release;
AEditor : = NIL ;
end ;
end ;
2007-10-26 18:19:55 +00:00
procedure TDetallesPresupuestoClienteController. 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-10-26 18:19:55 +00:00
end ;
end .