git-svn-id: https://192.168.0.254/svn/Proyectos.Tecsitel_FactuGES2/trunk@593 0c75b7a4-871f-7646-8a2f-f78d34cc349f
191 lines
8.0 KiB
ObjectPascal
191 lines
8.0 KiB
ObjectPascal
unit uDetallesFacturaProveedorController;
|
|
|
|
interface
|
|
|
|
uses
|
|
Classes, uDADataTable, uControllerDetallesArticulos, uBizDetallesFacturaProveedor, uIDataModuleFacturasProveedor,
|
|
uBizContactos, uBizArticulos;
|
|
|
|
const
|
|
CAMPO_REFERENCIA_FABRICANTE = 'REFERENCIA_FABRICANTE';
|
|
|
|
type
|
|
IDetallesFacturaProveedorController = interface(IControllerDetallesArticulos)
|
|
['{49F6199E-E031-42F5-AEA5-E70C3E3479A1}']
|
|
procedure AnadirArticulos(ADetalles: IDAStronglyTypedDataTable; AProveedor: IBizProveedor; const ANuevaFila :Boolean = True; const ACantidad: Integer = 1); overload;
|
|
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
|
|
function DarListaTiposDetalle: TStringList; override;
|
|
|
|
procedure AnadirArticulos(ADetalles: IDAStronglyTypedDataTable; AProveedor: IBizProveedor; const ANuevaFila :Boolean = True; const ACantidad: Integer = 1); overload;
|
|
procedure ActualizarDetalles(ADetalles: IDAStronglyTypedDataTable; AProveedor: IBizProveedor); overload;
|
|
procedure AnadirDetalleFacturaAsociadaAbono(ADetalles: IBizDetallesFacturaProveedor; AReferencia: String; AFecha: String);
|
|
constructor Create; override;
|
|
destructor Destroy; override;
|
|
end;
|
|
|
|
implementation
|
|
|
|
{ TDetallesFacturaProveedorController }
|
|
|
|
uses uDAInterfaces, Variants, uDataModuleFacturasProveedor, uArticulosFacturaProveedorController,
|
|
uControllerDetallesBase, Dialogs, SysUtils, uDialogUtils, uCalculosUtils, schArticulosClient_Intf,
|
|
schFacturasProveedorClient_Intf;
|
|
|
|
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í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;
|
|
|
|
procedure TDetallesFacturaProveedorController.AnadirArticulos(ADetalles: IDAStronglyTypedDataTable; AProveedor: IBizProveedor; const ANuevaFila :Boolean; const ACantidad: Integer);
|
|
var
|
|
AArticulos: IBizArticulo;
|
|
begin
|
|
if Assigned(ADetalles) then
|
|
begin
|
|
try
|
|
AArticulos := (FArticulosController.BuscarTodosPorProveedor as IBizArticulo);
|
|
|
|
//Si nueva fila es false, quiere decir que se sustituye un determinado artículo, por ello la lista a seleccionar no debe ser multiselect
|
|
if ANuevaFila then
|
|
begin
|
|
AArticulos := (FArticulosController as IArticulosFacturaProveedorController).ElegirArticulos(AArticulos, 'Elija los artículos que desea añadir a esta factura de Proveedor', True, AProveedor);
|
|
Add(ADetalles, AArticulos, ACantidad)
|
|
end
|
|
else
|
|
begin
|
|
AArticulos := (FArticulosController as IArticulosFacturaProveedorController).ElegirArticulos(AArticulos, 'Elija el artículo que desea añadir a esta factura de Proveedor', False, AProveedor);
|
|
RellenarDetalle(ADetalles, AArticulos, ACantidad);
|
|
end;
|
|
|
|
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;
|
|
|
|
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;
|
|
|
|
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);
|
|
var
|
|
AField: TDAField;
|
|
|
|
begin
|
|
if Assigned(AArticulos) then
|
|
ADetalles.DataTable.FieldByName(CAMPO_DESCUENTO).AsFloat := AArticulos.DESCUENTO
|
|
else
|
|
ADetalles.DataTable.FieldByName(CAMPO_DESCUENTO).AsFloat := 0;
|
|
|
|
//Sobreescribimos el id del articulo por el campo ID_ARTICULO que nos hemos tenido que crear para
|
|
//almacenar el codigo de artículo ya que ID esta destinado a ID_ARTICULO||ID_PROVEEDOR, para identificar de forma
|
|
//unica los articulos desglosados por proveedor.
|
|
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
|
|
ADetalles.DataTable.FieldByName(fld_FacturasProveedor_DetallesREFERENCIA_FABRICANTE).AsVariant := AField.AsVariant;
|
|
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.
|