2007-11-28 17:40:31 +00:00
unit uDetallesPresupuestoClienteController;
interface
uses
2009-06-30 16:39:42 +00:00
uDADataTable, uControllerDetallesBase, uControllerDetallesArticulos, uBizDetallesPresupuestoCliente, uIDataModulePresupuestosCliente,
2007-11-28 17:40:31 +00:00
uBizArticulos, uBizContactos;
type
IDetallesPresupuestoClienteController = interface( IControllerDetallesArticulos)
[ '{8D1D3559-E695-4962-9999-404B26B50D6C}' ]
2009-06-30 16:39:42 +00:00
procedure AnadirArticulos( ADetalles: IDAStronglyTypedDataTable; ACliente: IBizCliente; const ANuevaFila : Boolean = True ) ; overload ;
2007-11-28 17:40:31 +00:00
procedure ActualizarDetalles( ADetalles: IDAStronglyTypedDataTable; ACliente: IBizCliente) ; overload ;
procedure DesglosarPorteDetalles( ImportePorte: Currency ; ADetalles: IDAStronglyTypedDataTable) ;
function DarTotalPorteTotal( ADetalles: IDAStronglyTypedDataTable) : Double ;
2009-06-30 16:39:42 +00:00
function PedirDescuento: Variant ;
2009-07-09 09:23:03 +00:00
function DarPropiedades: IBizPropiedades;
2009-11-20 18:14:24 +00:00
procedure AnadirCapitulo ( const Tipo: String ; const Descripcion: String ; const Descuento: Boolean ; ADetalles: IDAStronglyTypedDataTable) ;
2012-05-23 11:49:20 +00:00
function BuscarCapitulo ( const Tipo: String ) : IBizCapitulo;
2009-08-10 11:32:12 +00:00
procedure SetTipoArticulo( ADetalles: IDAStronglyTypedDataTable; ATipo: String ) ;
2012-09-14 16:53:12 +00:00
procedure SetVisible( ADetalles: IDAStronglyTypedDataTable; const AVisible: Integer ; const Orden: Integer ) ; //1Ascendente/0Descendente
procedure SetVisible2( ADetalles: IDAStronglyTypedDataTable; const AVisible: Integer ; const Orden: Integer ) ;
2007-11-28 17:40:31 +00:00
end ;
TDetallesPresupuestoClienteController = class( TControllerDetallesArticulos, IDetallesPresupuestoClienteController)
private
FDataModule : IDataModulePresupuestosCliente;
2009-06-30 16:39:42 +00:00
function CreateEditor( const AName : String ; const IID: TGUID; out Intf) : Boolean ;
2007-11-28 17:40:31 +00:00
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
2009-06-30 16:39:42 +00:00
function PedirDescuento: Variant ;
procedure AnadirArticulos( ADetalles: IDAStronglyTypedDataTable; ACliente: IBizCliente; const ANuevaFila : Boolean = True ) ; reintroduce ; overload ;
2007-11-28 17:40:31 +00:00
procedure ActualizarDetalles( ADetalles: IDAStronglyTypedDataTable; ACliente: IBizCliente) ; overload ;
constructor Create; override ;
destructor Destroy; override ;
2009-07-09 09:23:03 +00:00
function DarPropiedades: IBizPropiedades;
2009-11-20 18:14:24 +00:00
procedure AnadirCapitulo ( const Tipo: String ; const Descripcion: String ; const Descuento: Boolean ; ADetalles: IDAStronglyTypedDataTable) ;
2009-07-09 09:23:03 +00:00
2012-05-23 11:49:20 +00:00
function BuscarCapitulo ( const Tipo: String ) : IBizCapitulo;
2009-07-09 09:23:03 +00:00
//Se sobre escribe para hacer otro recorrido y rellenar el tipo_articulo a todos los conceptos de los capitulos
procedure ValidarDetalles( ADataTable: IDAStronglyTypedDataTable) ; override ;
2009-08-10 11:32:12 +00:00
procedure SetTipoArticulo( ADetalles: IDAStronglyTypedDataTable; ATipo: String ) ;
2009-11-20 18:14:24 +00:00
procedure SetVisible( ADetalles: IDAStronglyTypedDataTable; const AVisible: Integer ; const Orden: Integer ) ; //1Ascendente/0Descendente
2012-09-14 16:53:12 +00:00
procedure SetVisible2( ADetalles: IDAStronglyTypedDataTable; const AVisible: Integer ; const Orden: Integer ) ;
2007-11-28 17:40:31 +00:00
end ;
implementation
2009-11-20 18:14:24 +00:00
uses DB, Controls, SysUtils, Dialogs, uDAInterfaces, uDialogUtils, Variants, uDataModulePresupuestosCliente,
2012-05-18 15:11:48 +00:00
uArticulosPresupuestoClienteController, schPresupuestosClienteClient_Intf,
2009-06-30 16:39:42 +00:00
uDataTableUtils, uCalculosUtils, uIEditorAsignarDescuento, uEditorRegistryUtils;
2007-11-28 17:40:31 +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) ;
2009-06-30 16:39:42 +00:00
ShowInfoMessage( 'Se ha actualizado el descuento para el cliente seleccionado' ) ;
2007-11-28 17:40:31 +00:00
finally
AArticulos : = Nil ;
end ;
end ;
end ;
2009-06-30 16:39:42 +00:00
procedure TDetallesPresupuestoClienteController. AnadirArticulos( ADetalles: IDAStronglyTypedDataTable; ACliente: IBizCliente; const ANuevaFila : Boolean ) ;
2007-11-28 17:40:31 +00:00
var
AArticulos: IBizArticulo;
begin
if Assigned( ADetalles) then
begin
try
AArticulos : = ( FArticulosController. BuscarTodos( ACliente) as IBizArticulo) ;
2009-06-30 16:39:42 +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-11-28 17:40:31 +00:00
finally
AArticulos : = Nil ;
end ;
end ;
end ;
2009-11-20 18:14:24 +00:00
procedure TDetallesPresupuestoClienteController. AnadirCapitulo( const Tipo: String ; const Descripcion: String ; const Descuento: Boolean ; ADetalles: IDAStronglyTypedDataTable) ;
2009-07-09 09:23:03 +00:00
var
ACapitulo: IBizCapitulo;
begin
Self. Add( ADetalles, TIPO_DETALLE_TITULO) ;
if not ADetalles. DataTable. Editing then
ADetalles. DataTable. Edit;
2009-11-20 18:14:24 +00:00
ADetalles. DataTable. FieldByName( fld_PresupuestosCliente_DetallesTIPO_ARTICULO) . AsString : = Tipo;
ADetalles. DataTable. FieldByName( fld_PresupuestosCliente_DetallesCONCEPTO) . AsString : = Descripcion;
2009-07-09 09:23:03 +00:00
//Rellenamos con las propiedades del capitulo
2009-11-20 18:14:24 +00:00
ACapitulo : = FDataModule. GetCapitulo( Tipo) ;
2009-07-09 09:23:03 +00:00
ACapitulo. DataTable. Active : = True ;
with ACapitulo. DataTable do
begin
First;
repeat
Self. Add( ADetalles, TIPO_DETALLE_CONCEPTO) ;
if not ADetalles. DataTable. Editing then
ADetalles. DataTable. Edit;
2009-11-20 18:14:24 +00:00
ADetalles. DataTable. FieldByName( fld_PresupuestosCliente_DetallesTIPO_ARTICULO) . AsString : = Tipo;
2012-05-23 11:49:20 +00:00
ADetalles. DataTable. FieldByName( fld_PresupuestosCliente_DetallesPROPIEDAD) . AsString : = ACapitulo. CONCEPTO;
2009-07-09 09:23:03 +00:00
Next;
until EOF;
end ;
Self. Add( ADetalles, TIPO_DETALLE_SUBTOTAL) ;
if not ADetalles. DataTable. Editing then
ADetalles. DataTable. Edit;
2009-11-20 18:14:24 +00:00
ADetalles. DataTable. FieldByName( fld_PresupuestosCliente_DetallesTIPO_ARTICULO) . AsString : = Tipo;
ADetalles. DataTable. FieldByName( fld_PresupuestosCliente_DetallesCONCEPTO) . AsString : = 'SUBTOTAL ' + Descripcion;
2009-10-26 18:12:48 +00:00
2009-11-20 18:14:24 +00:00
if Descuento then
begin
2009-10-26 18:12:48 +00:00
Self. Add( ADetalles, TIPO_DETALLE_DESCUENTO) ;
if not ADetalles. DataTable. Editing then
ADetalles. DataTable. Edit;
2009-11-20 18:14:24 +00:00
ADetalles. DataTable. FieldByName( fld_PresupuestosCliente_DetallesTIPO_ARTICULO) . AsString : = Tipo;
2009-10-26 18:12:48 +00:00
ADetalles. DataTable. FieldByName( fld_PresupuestosCliente_DetallesCONCEPTO) . AsString : = 'DESCUENTO ' ;
2009-07-09 09:23:03 +00:00
end ;
Self. Add( ADetalles, TIPO_DETALLE_CONCEPTO) ;
end ;
2007-11-28 17:40:31 +00:00
procedure TDetallesPresupuestoClienteController. AsignarController;
begin
FArticulosController : = TArticulosPresupuestoClienteController. Create;
end ;
2012-05-23 11:49:20 +00:00
function TDetallesPresupuestoClienteController. BuscarCapitulo( const Tipo: String ) : IBizCapitulo;
begin
Result : = FDataModule. GetCapitulo( Tipo) ;
end ;
2009-06-30 16:39:42 +00:00
function TDetallesPresupuestoClienteController. PedirDescuento: Variant ;
var
AEditor: IEditorAsignarDescuento;
begin
CreateEditor( 'EditorAsignarDescuento' , IEditorAsignarDescuento, AEditor) ;
if Assigned( AEditor) then
try
if ( AEditor. ShowModal = mrOk) then
Result : = AEditor. Descuento;
finally
AEditor. Release;
AEditor : = NIL ;
end ;
end ;
2007-11-28 17:40:31 +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 ;
}
function TDetallesPresupuestoClienteController. CalcularImporteTotalConcepto( DataTable: TDADataTable) : Double ;
begin
Result : = CalcularLineaConcepto( DataTable) ;
end ;
constructor TDetallesPresupuestoClienteController. Create;
begin
inherited ;
FDataModule : = TDataModulePresupuestosCliente. Create( Nil ) ;
end ;
2009-06-30 16:39:42 +00:00
function TDetallesPresupuestoClienteController. CreateEditor( const AName: String ; const IID: TGUID; out Intf) : Boolean ;
begin
Result : = Supports( EditorRegistry. CreateEditor( AName) , IID, Intf) ;
end ;
2009-07-09 09:23:03 +00:00
function TDetallesPresupuestoClienteController. DarPropiedades: IBizPropiedades;
begin
Result : = FDataModule. GetPropiedades;
end ;
2007-11-28 17:40:31 +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-06-30 16:39:42 +00:00
ActualizarTotales( ADetalles) ;
2007-11-28 17:40:31 +00:00
end ;
destructor TDetallesPresupuestoClienteController. Destroy;
begin
FDataModule : = Nil ;
inherited ;
end ;
procedure TDetallesPresupuestoClienteController. RellenarOtros( ADetalles: IDAStronglyTypedDataTable; AArticulos: IBizArticulo) ;
begin
2012-05-18 15:11:48 +00:00
ADetalles. DataTable. FieldByName( 'PROPIEDAD' ) . AsString : = AArticulos. FAMILIA;
2009-06-30 16:39:42 +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-28 17:40:31 +00:00
end ;
2009-08-10 11:32:12 +00:00
procedure TDetallesPresupuestoClienteController. SetTipoArticulo(
ADetalles: IDAStronglyTypedDataTable; ATipo: String ) ;
begin
if assigned( ADetalles) then
begin
ADetalles. DataTable. Edit;
ADetalles. DataTable. FieldByName( 'TIPO_ARTICULO' ) . AsString : = ATipo;
ADetalles. DataTable. Post;
end ;
end ;
2009-11-20 18:14:24 +00:00
procedure TDetallesPresupuestoClienteController. SetVisible( ADetalles: IDAStronglyTypedDataTable; const AVisible, Orden: Integer ) ;
var
ABookmark : TBookmark;
AuxPosicion: Integer ;
AuxEncontrado: Boolean ;
begin
AuxPosicion : = ADetalles. DataTable. FieldByName( CAMPO_POSICION) . AsInteger;
ABookmark : = ADetalles. DataTable. GetBookMark;
try
ADetalles. DataTable. DisableControls;
repeat
if ( Orden > 0 ) then
Inc( AuxPosicion)
else
Dec( AuxPosicion) ;
ADetalles. First;
AuxEncontrado : = ADetalles. Locate( CAMPO_POSICION, AuxPosicion, [ ] ) ;
if AuxEncontrado then
begin
ADetalles. DataTable. Edit;
ADetalles. DataTable. FieldByName( CAMPO_VISIBLE) . AsInteger : = AVisible;
ADetalles. DataTable. Post;
end ;
until ( ADetalles. DataTable. FieldByName( CAMPO_TIPO) . AsString = TIPO_DETALLE_SUBTOTAL)
or ( ADetalles. DataTable. FieldByName( CAMPO_TIPO) . AsString = TIPO_DETALLE_TITULO)
or ( ADetalles. DataTable. FieldByName( CAMPO_TIPO) . AsString = TIPO_DETALLE_TITULO_OPCIONAL)
or ( AuxEncontrado = False )
finally
ADetalles. DataTable. GotoBookmark( ABookmark) ;
ADetalles. DataTable. FreeBookmark( ABookmark) ;
ADetalles. DataTable. EnableControls;
end ;
end ;
2012-09-14 16:53:12 +00:00
procedure TDetallesPresupuestoClienteController. SetVisible2(
ADetalles: IDAStronglyTypedDataTable; const AVisible, Orden: Integer ) ;
var
ABookmark : TBookmark;
AuxPosicion: Integer ;
AuxEncontrado: Boolean ;
begin
AuxPosicion : = ADetalles. DataTable. FieldByName( CAMPO_POSICION) . AsInteger;
ABookmark : = ADetalles. DataTable. GetBookMark;
try
ADetalles. DataTable. DisableControls;
repeat
if ( Orden > 0 ) then
Inc( AuxPosicion)
else
Dec( AuxPosicion) ;
ADetalles. First;
AuxEncontrado : = ADetalles. Locate( CAMPO_POSICION, AuxPosicion, [ ] ) ;
if AuxEncontrado then
begin
ADetalles. DataTable. Edit;
ADetalles. DataTable. FieldByName( CAMPO_VISIBLE2) . AsInteger : = AVisible;
ADetalles. DataTable. Post;
end ;
until ( ADetalles. DataTable. FieldByName( CAMPO_TIPO) . AsString = TIPO_DETALLE_SUBTOTAL)
or ( ADetalles. DataTable. FieldByName( CAMPO_TIPO) . AsString = TIPO_DETALLE_TITULO)
or ( ADetalles. DataTable. FieldByName( CAMPO_TIPO) . AsString = TIPO_DETALLE_TITULO_OPCIONAL)
or ( AuxEncontrado = False )
finally
ADetalles. DataTable. GotoBookmark( ABookmark) ;
ADetalles. DataTable. FreeBookmark( ABookmark) ;
ADetalles. DataTable. EnableControls;
end ;
end ;
2007-11-28 17:40:31 +00:00
procedure TDetallesPresupuestoClienteController. ValidarCampos( DataTable: TDADataTable) ;
begin
inherited ;
ValidarCamposLineaConcepto( DataTable) ;
end ;
2009-07-09 09:23:03 +00:00
procedure TDetallesPresupuestoClienteController. ValidarDetalles( ADataTable: IDAStronglyTypedDataTable) ;
var
AuxTipoArticulo : String ;
AuxPosicionIni : Integer ;
AuxPosicion : Integer ;
begin
inherited ;
AuxTipoArticulo : = '' ;
AuxPosicionIni : = ADataTable. DataTable. FieldByName( CAMPO_POSICION) . AsInteger;
AuxPosicion : = 0 ;
BeginUpdate( ADataTable) ;
try
ADataTable. DataTable. First;
while ADataTable. DataTable. Locate( CAMPO_POSICION, AuxPosicion, [ ] ) do
begin
if ( ADataTable. DataTable. FieldByName( CAMPO_TIPO) . AsString = TIPO_DETALLE_TITULO) then
AuxTipoArticulo : = ADataTable. DataTable. FieldByName( fld_CapitulosPresupuestoTIPO_ARTICULO) . AsString
else if ( ADataTable. DataTable. FieldByName( CAMPO_TIPO) . AsString = TIPO_DETALLE_SUBTOTAL) then
AuxTipoArticulo : = ''
else if ( ADataTable. DataTable. FieldByName( CAMPO_TIPO) . AsString = TIPO_DETALLE_CONCEPTO) then
if ( Length( AuxTipoArticulo) > 0 ) then
begin
if not ADataTable. DataTable. Editing then
ADataTable. DataTable. Edit;
ADataTable. DataTable. FieldByName( fld_CapitulosPresupuestoTIPO_ARTICULO) . AsString : = AuxTipoArticulo;
ADataTable. DataTable. Post;
end ;
Inc( AuxPosicion) ;
ADataTable. DataTable. First;
end ;
finally
//Dejamos el puntero en la misma posici<63> n que la que parti<74>
ADataTable. DataTable. Locate( CAMPO_POSICION, AuxPosicionIni, [ ] ) ;
EndUpdate( ADataTable) ;
end ;
end ;
2007-11-28 17:40:31 +00:00
procedure TDetallesPresupuestoClienteController. RellenarImportes( ADetalles: IDAStronglyTypedDataTable; AArticulos: IBizArticulo) ;
begin
2012-04-13 11:33:18 +00:00
//Para acana el importa a cargar en la lista ser<65> siempre el precio PVP
2009-06-30 16:39:42 +00:00
if ADetalles. DataTable. FieldByName( CAMPO_IMPORTE_UNIDAD) . IsNull then
if Assigned( AArticulos) then
2012-04-13 11:33:18 +00:00
ADetalles. DataTable. FieldByName( CAMPO_IMPORTE_UNIDAD) . AsVariant : = AArticulos. PRECIO_PVP
2009-06-30 16:39:42 +00:00
else
ADetalles. DataTable. FieldByName( CAMPO_IMPORTE_UNIDAD) . AsVariant : = Null;
2007-11-28 17:40:31 +00:00
end ;
end .