2007-11-16 20:58:56 +00:00
unit uDetallesFacturaProveedorController;
interface
uses
2008-09-17 18:38:38 +00:00
Classes, uDADataTable, uControllerDetallesArticulos, uBizDetallesFacturaProveedor, uIDataModuleFacturasProveedor,
2007-11-16 20:58:56 +00:00
uBizContactos, uBizArticulos;
2008-07-22 11:21:06 +00:00
const
CAMPO_REFERENCIA_FABRICANTE = 'REFERENCIA_FABRICANTE' ;
2007-11-16 20:58:56 +00:00
type
IDetallesFacturaProveedorController = interface( IControllerDetallesArticulos)
[ '{49F6199E-E031-42F5-AEA5-E70C3E3479A1}' ]
2008-02-06 18:02:35 +00:00
procedure AnadirArticulos( ADetalles: IDAStronglyTypedDataTable; AProveedor: IBizProveedor; const ANuevaFila : Boolean = True ; const ACantidad: Integer = 1 ) ; overload ;
2007-11-16 20:58:56 +00:00
procedure ActualizarDetalles( ADetalles: IDAStronglyTypedDataTable; AProveedor: IBizProveedor) ;
procedure AnadirDetalleFacturaAsociadaAbono( ADetalles: IBizDetallesFacturaProveedor; AReferencia: String ; AFecha: String ) ;
procedure DesglosarPorteDetalles( ImportePorte: Currency ; ADetalles: IDAStronglyTypedDataTable) ;
function DarTotalPorteTotal( ADetalles: IDAStronglyTypedDataTable) : Double ;
end ;
TDetallesFacturaProveedorController = class( TControllerDetallesArticulos, IDetallesFacturaProveedorController)
private
FDataModule : IDataModuleFacturasProveedor;
protected
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; AProveedor: IBizProveedor; const ANuevaFila : Boolean = True ; const ACantidad: Integer = 1 ) ; overload ;
2007-11-16 20:58:56 +00:00
procedure ActualizarDetalles( ADetalles: IDAStronglyTypedDataTable; AProveedor: IBizProveedor) ; overload ;
procedure AnadirDetalleFacturaAsociadaAbono( ADetalles: IBizDetallesFacturaProveedor; AReferencia: String ; AFecha: String ) ;
constructor Create; override ;
destructor Destroy; override ;
end ;
implementation
{ TDetallesFacturaProveedorController }
2008-07-30 16:25:35 +00:00
uses uDAInterfaces, Variants, uDataModuleFacturasProveedor, uArticulosFacturaProveedorController,
2008-08-04 14:51:21 +00:00
uControllerDetallesBase, Dialogs, SysUtils, uDialogUtils, uCalculosUtils, schArticulosClient_Intf,
schFacturasProveedorClient_Intf;
2007-11-16 20:58:56 +00:00
procedure TDetallesFacturaProveedorController. ActualizarDetalles( ADetalles: IDAStronglyTypedDataTable; AProveedor: IBizProveedor) ;
var
AArticulos : IBizArticulo;
begin
if Assigned( ADetalles) then
begin
try
AArticulos : = ( FArticulosController. BuscarTodos( AProveedor) as IBizArticulo) ;
ActualizarDetalles( ADetalles, AArticulos) ;
EliminarArticulosProveedor( ADetalles) ;
ShowInfoMessage( 'Se han eliminado todos los art<72> culos que no pertenecen al nuevo proveedor seleccionado, y los que pertenecen sus descuentos han sido adaptados al proveedor seleccionado' ) ;
finally
AArticulos : = Nil ;
end ;
end ;
end ;
2008-02-06 18:02:35 +00:00
procedure TDetallesFacturaProveedorController. AnadirArticulos( ADetalles: IDAStronglyTypedDataTable; AProveedor: IBizProveedor; const ANuevaFila : Boolean ; const ACantidad: Integer ) ;
2007-11-16 20:58:56 +00:00
var
AArticulos: IBizArticulo;
begin
if Assigned( ADetalles) then
begin
try
2008-07-22 11:21:06 +00:00
AArticulos : = ( FArticulosController. BuscarTodosPorProveedor 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 IArticulosFacturaProveedorController) . ElegirArticulos( AArticulos, 'Elija los art<72> culos que desea a<> adir a esta factura de Proveedor' , True , AProveedor) ;
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 IArticulosFacturaProveedorController) . ElegirArticulos( AArticulos, 'Elija el art<72> culo que desea a<> adir a esta factura de Proveedor' , False , AProveedor) ;
2008-02-06 18:02:35 +00:00
RellenarDetalle( ADetalles, AArticulos, ACantidad) ;
2008-02-05 20:38:38 +00:00
end ;
2007-11-16 20:58:56 +00:00
finally
AArticulos : = Nil ;
end ;
end ;
end ;
procedure TDetallesFacturaProveedorController. AnadirDetalleFacturaAsociadaAbono(
ADetalles: IBizDetallesFacturaProveedor; AReferencia, AFecha: String ) ;
begin
AnadirConceptoInicial( ADetalles, 'ABONO DE FACTURA ' + AReferencia + ' con fecha ' + AFecha) ;
end ;
procedure TDetallesFacturaProveedorController. AsignarController;
begin
FArticulosController : = TArticulosFacturaProveedorController. Create;
end ;
function TDetallesFacturaProveedorController. CalcularImporteTotalConcepto( DataTable: TDADataTable) : Double ;
begin
Result : = CalcularLineaConcepto( DataTable) ;
end ;
constructor TDetallesFacturaProveedorController. Create;
begin
inherited ;
FDataModule : = TDataModuleFacturasProveedor. Create( Nil ) ;
end ;
2008-09-17 18:38:38 +00:00
function TDetallesFacturaProveedorController. 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-16 20:58:56 +00:00
function TDetallesFacturaProveedorController. DarTotalPorteTotal( ADetalles: IDAStronglyTypedDataTable) : Double ;
begin
Result : = DarTotalPorte( ADetalles) ;
end ;
procedure TDetallesFacturaProveedorController. DesglosarPorteDetalles( ImportePorte: Currency ; ADetalles: IDAStronglyTypedDataTable) ;
begin
DesglosarPorte( ImportePorte, ADetalles) ;
ActualizarTotales( ADetalles) ;
end ;
destructor TDetallesFacturaProveedorController. Destroy;
begin
FDataModule : = Nil ;
inherited ;
end ;
procedure TDetallesFacturaProveedorController. RellenarOtros( ADetalles: IDAStronglyTypedDataTable; AArticulos: IBizArticulo) ;
2008-07-30 16:25:35 +00:00
var
AField: TDAField;
2007-11-16 20:58:56 +00:00
begin
if Assigned( AArticulos) then
ADetalles. DataTable. FieldByName( CAMPO_DESCUENTO) . AsFloat : = AArticulos. DESCUENTO
else
ADetalles. DataTable. FieldByName( CAMPO_DESCUENTO) . AsFloat : = 0 ;
2008-07-22 11:21:06 +00:00
//Sobreescribimos el id del articulo por el campo ID_ARTICULO que nos hemos tenido que crear para
//almacenar el codigo de art<72> culo ya que ID esta destinado a ID_ARTICULO||ID_PROVEEDOR, para identificar de forma
//unica los articulos desglosados por proveedor.
2008-07-30 16:25:35 +00:00
AField : = AArticulos. DataTable. FindField( CAMPO_ID_ARTICULOS) ;
if Assigned( AField) then
ADetalles. DataTable. FieldByName( CAMPO_ID_ARTICULOS) . AsVariant : = AField. AsVariant;
AField : = AArticulos. DataTable. FindField( fld_ArticulosREFERENCIA_FABR) ;
if Assigned( AField) then
2008-08-04 14:51:21 +00:00
ADetalles. DataTable. FieldByName( fld_FacturasProveedor_DetallesREFERENCIA_FABRICANTE) . AsVariant : = AField. AsVariant;
2007-11-16 20:58:56 +00:00
end ;
procedure TDetallesFacturaProveedorController. ValidarCampos( DataTable: TDADataTable) ;
begin
inherited ;
ValidarCamposLineaConcepto( DataTable) ;
end ;
procedure TDetallesFacturaProveedorController. RellenarImportes( ADetalles: IDAStronglyTypedDataTable; AArticulos: IBizArticulo) ;
begin
if Assigned( AArticulos) then
begin
ADetalles. DataTable. FieldByName( CAMPO_IMPORTE_UNIDAD) . AsVariant : = AArticulos. PRECIO_COSTE;
ADetalles. DataTable. FieldByName( CAMPO_IMPORTE_PORTE) . AsVariant : = AArticulos. PRECIO_PORTE
end
else
begin
ADetalles. DataTable. FieldByName( CAMPO_IMPORTE_UNIDAD) . AsVariant : = Null;
ADetalles. DataTable. FieldByName( CAMPO_IMPORTE_PORTE) . AsVariant : = Null
end ;
end ;
end .