453 lines
14 KiB
ObjectPascal
453 lines
14 KiB
ObjectPascal
|
|
unit uEditorFacturasProveedor;
|
|||
|
|
|
|||
|
|
interface
|
|||
|
|
|
|||
|
|
uses
|
|||
|
|
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
|
|||
|
|
Dialogs, Menus, DB, uDADataTable, JvAppStorage,
|
|||
|
|
JvAppRegistryStorage, JvComponent, JvFormPlacement, ImgList,
|
|||
|
|
PngImageList, StdActns, ActnList, ComCtrls, TB2ExtItems, TBXExtItems,
|
|||
|
|
TBX, TB2Item, TB2Dock, TB2Toolbar, ExtCtrls, JvExControls,
|
|||
|
|
JvNavigationPane, uViewGrid, pngimage, JvComponentBase,
|
|||
|
|
uEditorGridBase, uBizFacturasProveedor, uIEditorFacturasProveedor,
|
|||
|
|
uFacturasProveedorController, uCustomView, uViewBase, uViewBarraSeleccion,
|
|||
|
|
uViewGridBase, JvExComCtrls, JvStatusBar, JSDialog,
|
|||
|
|
uViewFacturasProveedor, uDAInterfaces, dxGDIPlusClasses;
|
|||
|
|
|
|||
|
|
type
|
|||
|
|
|
|||
|
|
TfEditorFacturasProveedor = class(TfEditorGridBase, IEditorFacturasProveedor)
|
|||
|
|
JsNuevaFacturaDialog: TJSDialog;
|
|||
|
|
JsListaFacturasGeneradas: TJSDialog;
|
|||
|
|
frViewFacturasProveedor1: TfrViewFacturasProveedor;
|
|||
|
|
actNuevaFactura: TAction;
|
|||
|
|
actNuevoAbono: TAction;
|
|||
|
|
JsNuevoAbonoDialog: TJSDialog;
|
|||
|
|
TBXSubmenuItem2: TTBXSubmenuItem;
|
|||
|
|
TBXItem38: TTBXItem;
|
|||
|
|
TBXItem39: TTBXItem;
|
|||
|
|
JsPrevisualizarDialog: TJSDialog;
|
|||
|
|
JsImprimirDialog: TJSDialog;
|
|||
|
|
JsListaFacturasNoEliminadas: TJSDialog;
|
|||
|
|
actInformes: TAction;
|
|||
|
|
TBXItem40: TTBXItem;
|
|||
|
|
JSInformesDialog: TJSDialog;
|
|||
|
|
procedure FormShow(Sender: TObject);
|
|||
|
|
procedure actEliminarUpdate(Sender: TObject);
|
|||
|
|
procedure actNuevaFacturaExecute(Sender: TObject);
|
|||
|
|
procedure actNuevoAbonoExecute(Sender: TObject);
|
|||
|
|
procedure actInformesExecute(Sender: TObject);
|
|||
|
|
procedure OnListaAnosChange(Sender: TObject; const Text: string);
|
|||
|
|
|
|||
|
|
private
|
|||
|
|
FFacturas: IBizFacturaProveedor;
|
|||
|
|
FController : IFacturasProveedorController;
|
|||
|
|
|
|||
|
|
protected
|
|||
|
|
function GetFacturas: IBizFacturaProveedor;
|
|||
|
|
procedure SetFacturas(const Value: IBizFacturaProveedor);
|
|||
|
|
|
|||
|
|
function GetController : IFacturasProveedorController; virtual;
|
|||
|
|
procedure SetController (const Value : IFacturasProveedorController); virtual;
|
|||
|
|
|
|||
|
|
procedure NuevoInterno; override;
|
|||
|
|
procedure EliminarInterno; override;
|
|||
|
|
procedure ModificarInterno; override;
|
|||
|
|
procedure DuplicarInterno; override;
|
|||
|
|
procedure ImprimirInterno; override;
|
|||
|
|
procedure PrevisualizarInterno; override;
|
|||
|
|
procedure RefrescarInterno; override;
|
|||
|
|
|
|||
|
|
public
|
|||
|
|
procedure PonerTitulos(const ATitulo: string = ''); override;
|
|||
|
|
property Facturas: IBizFacturaProveedor read GetFacturas write SetFacturas;
|
|||
|
|
property Controller : IFacturasProveedorController read GetController write SetController;
|
|||
|
|
constructor Create(AOwner: TComponent); override;
|
|||
|
|
destructor Destroy; override;
|
|||
|
|
end;
|
|||
|
|
|
|||
|
|
|
|||
|
|
implementation
|
|||
|
|
|
|||
|
|
uses
|
|||
|
|
uDataModuleFacturasProveedor, uDataModuleUsuarios,
|
|||
|
|
uGridUtils, uDBSelectionListUtils, uFactuGES_App, uBizEjercicios,
|
|||
|
|
uAlbaranesProveedorController, uBizAlbaranesProveedor,
|
|||
|
|
uEditorBase, uGestorInformesController;
|
|||
|
|
|
|||
|
|
// , uGenerarFacturasProvAlbProvUtils;
|
|||
|
|
|
|||
|
|
{$R *.dfm}
|
|||
|
|
|
|||
|
|
{
|
|||
|
|
*************************** TfEditorFacturasProveedor ***************************
|
|||
|
|
}
|
|||
|
|
procedure TfEditorFacturasProveedor.actEliminarUpdate(Sender: TObject);
|
|||
|
|
begin
|
|||
|
|
inherited;
|
|||
|
|
if (Sender as TAction).Enabled then
|
|||
|
|
(Sender as TAction).Enabled := (FFacturas.SITUACION = CTE_PENDIENTE);
|
|||
|
|
end;
|
|||
|
|
|
|||
|
|
procedure TfEditorFacturasProveedor.actInformesExecute(Sender: TObject);
|
|||
|
|
var
|
|||
|
|
Respuesta : Integer;
|
|||
|
|
AGestorInformesController : IGestorInformesController;
|
|||
|
|
|
|||
|
|
begin
|
|||
|
|
AGestorInformesController := TGestorInformesController.Create;
|
|||
|
|
try
|
|||
|
|
|
|||
|
|
Respuesta := JsInformesDialog.Execute;
|
|||
|
|
|
|||
|
|
if Respuesta <> IDCANCEL then
|
|||
|
|
begin
|
|||
|
|
case JsInformesDialog.CustomButtonResult of
|
|||
|
|
100 : begin // Listado de facturas pendientes
|
|||
|
|
AGestorInformesController.VerInformeListadoFacturasProvPendientes;
|
|||
|
|
end;
|
|||
|
|
200 : begin // Listado de IVA
|
|||
|
|
AGestorInformesController.VerInformeIVAProveedores;
|
|||
|
|
end;
|
|||
|
|
300 : begin // Listado de facturas de cliente
|
|||
|
|
AGestorInformesController.VerInformeListadoFacturasProv;
|
|||
|
|
end;
|
|||
|
|
end;
|
|||
|
|
end;
|
|||
|
|
|
|||
|
|
finally
|
|||
|
|
AGestorInformesController := NIL;
|
|||
|
|
end;
|
|||
|
|
end;
|
|||
|
|
|
|||
|
|
procedure TfEditorFacturasProveedor.actNuevaFacturaExecute(Sender: TObject);
|
|||
|
|
begin
|
|||
|
|
actNuevo.Execute;
|
|||
|
|
end;
|
|||
|
|
|
|||
|
|
procedure TfEditorFacturasProveedor.actNuevoAbonoExecute(Sender: TObject);
|
|||
|
|
var
|
|||
|
|
Respuesta : Integer;
|
|||
|
|
Opcion : Integer;
|
|||
|
|
// FPedidosClienteController : IPedidosClienteController;
|
|||
|
|
// APedido : IBizPedidoCliente;
|
|||
|
|
// FAlbaranesClienteController : IAlbaranesClienteController;
|
|||
|
|
// AAlbaranes : IBizAlbaranCliente;
|
|||
|
|
// AFacturasNuevas : IBizFacturaCliente;
|
|||
|
|
/// i : integer;
|
|||
|
|
begin
|
|||
|
|
inherited;
|
|||
|
|
//ABONOS
|
|||
|
|
if (Facturas.TIPO = CTE_TIPO_FACTURA) then
|
|||
|
|
begin
|
|||
|
|
Respuesta := JsNuevoAbonoDialog.Execute;
|
|||
|
|
//Nos salimos sin hace nada
|
|||
|
|
if Respuesta = IDCANCEL then
|
|||
|
|
Exit;
|
|||
|
|
Opcion := JsNuevoAbonoDialog.CustomButtonResult;
|
|||
|
|
end
|
|||
|
|
else
|
|||
|
|
Opcion := 100;
|
|||
|
|
|
|||
|
|
case Opcion of
|
|||
|
|
200 : begin // Utilizar factura seleccionada
|
|||
|
|
FController.Ver(FController.GenerarAbono(Facturas));
|
|||
|
|
actRefrescar.Execute;
|
|||
|
|
ViewGrid._FocusedView.DataController.GotoFirst;
|
|||
|
|
end;
|
|||
|
|
100 : begin // Abono nuevo vacio
|
|||
|
|
if FController.AnadirAbono(Facturas) then
|
|||
|
|
FController.Ver(Facturas);
|
|||
|
|
end;
|
|||
|
|
end;
|
|||
|
|
end;
|
|||
|
|
|
|||
|
|
constructor TfEditorFacturasProveedor.Create(AOwner: TComponent);
|
|||
|
|
begin
|
|||
|
|
inherited;
|
|||
|
|
ViewGrid := frViewFacturasProveedor1; // CreateView(TfrViewFacturasProveedor) as IViewFacturasProveedor;
|
|||
|
|
end;
|
|||
|
|
|
|||
|
|
destructor TfEditorFacturasProveedor.Destroy;
|
|||
|
|
begin
|
|||
|
|
FFacturas := NIL;
|
|||
|
|
inherited;
|
|||
|
|
end;
|
|||
|
|
|
|||
|
|
procedure TfEditorFacturasProveedor.DuplicarInterno;
|
|||
|
|
var
|
|||
|
|
AFactura : IBizFacturaProveedor;
|
|||
|
|
begin
|
|||
|
|
inherited;
|
|||
|
|
AFactura := FController.Duplicar(FFacturas);
|
|||
|
|
try
|
|||
|
|
FController.Ver(AFactura);
|
|||
|
|
finally
|
|||
|
|
actRefrescar.Execute;
|
|||
|
|
end;
|
|||
|
|
end;
|
|||
|
|
|
|||
|
|
procedure TfEditorFacturasProveedor.EliminarInterno;
|
|||
|
|
var
|
|||
|
|
ACadena : String;
|
|||
|
|
AFacturas: IBizFacturaProveedor;
|
|||
|
|
AllItems: Boolean;
|
|||
|
|
AListaCausas: TStringList;
|
|||
|
|
|
|||
|
|
begin
|
|||
|
|
AFacturas := Nil;
|
|||
|
|
AllItems := False;
|
|||
|
|
AListaCausas := TStringList.Create;
|
|||
|
|
|
|||
|
|
if MultiSelect and Assigned(ViewGrid) then
|
|||
|
|
AllItems := (ViewGrid.NumSeleccionados > 1);
|
|||
|
|
|
|||
|
|
if AllItems then
|
|||
|
|
begin
|
|||
|
|
if (Application.MessageBox('¿Desea borrar las facturas/abonos de cliente seleccionados?', 'Atención', MB_YESNO) = IDYES) then
|
|||
|
|
begin
|
|||
|
|
SeleccionarFilasDesdeGrid(ViewGrid._FocusedView, (Facturas as ISeleccionable).SelectedRecords);
|
|||
|
|
AFacturas := (Controller as IFacturasProveedorController).ExtraerSeleccionados(Facturas) as IBizFacturaProveedor;
|
|||
|
|
end
|
|||
|
|
end
|
|||
|
|
else begin
|
|||
|
|
if Facturas.TIPO = CTE_TIPO_FACTURA then
|
|||
|
|
ACadena := '¿Desea borrar esta factura de proveedor?'
|
|||
|
|
else
|
|||
|
|
ACadena := '¿Desea borrar este abono a proveedor?';
|
|||
|
|
|
|||
|
|
if (Application.MessageBox(PChar(ACadena), 'Atención', MB_YESNO) = IDYES) then
|
|||
|
|
AFacturas := Facturas;
|
|||
|
|
end;
|
|||
|
|
|
|||
|
|
if Assigned(AFacturas) then
|
|||
|
|
begin
|
|||
|
|
if (not FController.Eliminar(AFacturas, AllItems, AListaCausas))
|
|||
|
|
//En el caso de querer borrar una factura pendiente cuyos recibos tienen devoluciones
|
|||
|
|
and (not AllItems) then
|
|||
|
|
begin
|
|||
|
|
JsListaFacturasNoEliminadas.Content.Clear;
|
|||
|
|
JsListaFacturasNoEliminadas.Content.Add('Ref. factura: ' + AFacturas.REFERENCIA + ' ' + AFacturas.NOMBRE);
|
|||
|
|
if Length(VarToStr(AListaCausas.Values[IntToStr(AFacturas.ID)])) > 0 then
|
|||
|
|
JsListaFacturasNoEliminadas.Content.Add(VarToStr(AListaCausas.Values[IntToStr(AFacturas.ID)]))
|
|||
|
|
else
|
|||
|
|
JsListaFacturasNoEliminadas.Content.Add('La factura puede tener algún recibo devuelto y no puede ser eliminada');
|
|||
|
|
JsListaFacturasNoEliminadas.Execute;
|
|||
|
|
end;
|
|||
|
|
|
|||
|
|
if AllItems then
|
|||
|
|
begin
|
|||
|
|
if (AFacturas.DataTable.RecordCount > 0) then
|
|||
|
|
begin
|
|||
|
|
with AFacturas.DataTable do
|
|||
|
|
begin
|
|||
|
|
JsListaFacturasNoEliminadas.Content.Clear;
|
|||
|
|
First;
|
|||
|
|
while not EOF do
|
|||
|
|
begin
|
|||
|
|
JsListaFacturasNoEliminadas.Content.Add('Ref. factura: ' + AFacturas.REFERENCIA + ' ' + AFacturas.NOMBRE);
|
|||
|
|
if Length(AListaCausas.Values[IntToStr(AFacturas.ID)]) > 0 then
|
|||
|
|
JsListaFacturasNoEliminadas.Content.Add(VarToStr(AListaCausas.Values[IntToStr(AFacturas.ID)]))
|
|||
|
|
else
|
|||
|
|
JsListaFacturasNoEliminadas.Content.Add('La factura puede tener algún recibo devuelto y no puede ser eliminada');
|
|||
|
|
JsListaFacturasNoEliminadas.Content.Add('');
|
|||
|
|
Next;
|
|||
|
|
end;
|
|||
|
|
end;
|
|||
|
|
JsListaFacturasNoEliminadas.Execute;
|
|||
|
|
end;
|
|||
|
|
actRefrescar.Execute;
|
|||
|
|
end;
|
|||
|
|
end;
|
|||
|
|
|
|||
|
|
AListaCausas.Free;
|
|||
|
|
ViewGrid.GotoFirst;
|
|||
|
|
end;
|
|||
|
|
|
|||
|
|
procedure TfEditorFacturasProveedor.FormShow(Sender: TObject);
|
|||
|
|
begin
|
|||
|
|
cbxListaAnos.OnChange := OnListaAnosChange; //OJO SIEMPRE ANTES DEL INHERITED
|
|||
|
|
|
|||
|
|
inherited;
|
|||
|
|
|
|||
|
|
if not Assigned(ViewGrid) then
|
|||
|
|
raise Exception.Create('No hay ninguna vista asignada');
|
|||
|
|
|
|||
|
|
if not Assigned(Facturas) then
|
|||
|
|
raise Exception.Create('No hay ninguna facturas asignada');
|
|||
|
|
|
|||
|
|
Facturas.DataTable.Active := True;
|
|||
|
|
ViewGrid.GotoFirst;
|
|||
|
|
end;
|
|||
|
|
|
|||
|
|
function TfEditorFacturasProveedor.GetController: IFacturasProveedorController;
|
|||
|
|
begin
|
|||
|
|
Result := FController;
|
|||
|
|
end;
|
|||
|
|
|
|||
|
|
function TfEditorFacturasProveedor.GetFacturas: IBizFacturaProveedor;
|
|||
|
|
begin
|
|||
|
|
Result := FFacturas;
|
|||
|
|
end;
|
|||
|
|
|
|||
|
|
procedure TfEditorFacturasProveedor.ImprimirInterno;
|
|||
|
|
{var
|
|||
|
|
Respuesta : Integer;
|
|||
|
|
AFacturas: IBizFacturaProveedor;
|
|||
|
|
AllItems: Boolean;}
|
|||
|
|
begin
|
|||
|
|
|
|||
|
|
//Solo se podrá imprimir la lista de facturas de proveedor visibles de momento
|
|||
|
|
inherited;
|
|||
|
|
|
|||
|
|
|
|||
|
|
{
|
|||
|
|
AFacturas := Nil;
|
|||
|
|
AllItems := False;
|
|||
|
|
|
|||
|
|
if MultiSelect and Assigned(ViewGrid) then
|
|||
|
|
AllItems := (ViewGrid.NumSeleccionados > 1);
|
|||
|
|
|
|||
|
|
//Si esta agrupado solo podré imprimir la lista de elementos visibles
|
|||
|
|
if not ViewGrid.esSeleccionCeldaDatos then
|
|||
|
|
inherited
|
|||
|
|
else
|
|||
|
|
begin
|
|||
|
|
Respuesta := JsImprimirDialog.Execute;
|
|||
|
|
if Respuesta <> IDCANCEL then
|
|||
|
|
begin
|
|||
|
|
case JsImprimirDialog.CustomButtonResult of
|
|||
|
|
200 : begin // Lista de elementos visibles
|
|||
|
|
inherited;
|
|||
|
|
end;
|
|||
|
|
100 : begin // Elemento Seleccionado
|
|||
|
|
if AllItems then
|
|||
|
|
begin
|
|||
|
|
SeleccionarFilasDesdeGrid(ViewGrid._FocusedView, (Facturas as ISeleccionable).SelectedRecords);
|
|||
|
|
AFacturas := (Controller as IFacturasProveedorController).ExtraerSeleccionados(Facturas) as IBizFacturaProveedor;
|
|||
|
|
end
|
|||
|
|
else
|
|||
|
|
AFacturas := Facturas;
|
|||
|
|
|
|||
|
|
if Assigned(AFacturas) then
|
|||
|
|
FController.Print(AFacturas, AllItems);
|
|||
|
|
end;
|
|||
|
|
end;
|
|||
|
|
end;
|
|||
|
|
end;
|
|||
|
|
}
|
|||
|
|
end;
|
|||
|
|
|
|||
|
|
procedure TfEditorFacturasProveedor.ModificarInterno;
|
|||
|
|
begin
|
|||
|
|
inherited;
|
|||
|
|
FController.Ver(Facturas);
|
|||
|
|
end;
|
|||
|
|
|
|||
|
|
procedure TfEditorFacturasProveedor.NuevoInterno;
|
|||
|
|
begin
|
|||
|
|
inherited;
|
|||
|
|
|
|||
|
|
if FController.Anadir(Facturas) then
|
|||
|
|
FController.Ver(Facturas);
|
|||
|
|
end;
|
|||
|
|
|
|||
|
|
procedure TfEditorFacturasProveedor.OnListaAnosChange(Sender: TObject; const Text: string);
|
|||
|
|
begin
|
|||
|
|
Controller.FiltrarAno(Facturas, DynWhereDataTable, Text);
|
|||
|
|
if Facturas.DataTable.Active then
|
|||
|
|
RefrescarInterno;
|
|||
|
|
end;
|
|||
|
|
|
|||
|
|
procedure TfEditorFacturasProveedor.PonerTitulos(const ATitulo: string);
|
|||
|
|
var
|
|||
|
|
FTitulo : String;
|
|||
|
|
begin
|
|||
|
|
FTitulo := 'Lista de facturas de proveedor - ' + AppFactuGES.EmpresaActiva.NOMBRE;
|
|||
|
|
inherited PonerTitulos(FTitulo);
|
|||
|
|
end;
|
|||
|
|
|
|||
|
|
procedure TfEditorFacturasProveedor.PrevisualizarInterno;
|
|||
|
|
{
|
|||
|
|
var
|
|||
|
|
Respuesta : Integer;
|
|||
|
|
AFacturas: IBizFacturaProveedor;
|
|||
|
|
AllItems: Boolean;
|
|||
|
|
}
|
|||
|
|
begin
|
|||
|
|
|
|||
|
|
//Solo se podrá imprimir la lista de facturas de proveedor visibles de momento
|
|||
|
|
inherited;
|
|||
|
|
|
|||
|
|
{
|
|||
|
|
AFacturas := Nil;
|
|||
|
|
AllItems := False;
|
|||
|
|
|
|||
|
|
if MultiSelect and Assigned(ViewGrid) then
|
|||
|
|
AllItems := (ViewGrid.NumSeleccionados > 1);
|
|||
|
|
|
|||
|
|
//Si esta agrupado solo podré imprimir la lista de elementos visibles
|
|||
|
|
if not ViewGrid.esSeleccionCeldaDatos then
|
|||
|
|
inherited
|
|||
|
|
else
|
|||
|
|
begin
|
|||
|
|
Respuesta := JsPrevisualizarDialog.Execute;
|
|||
|
|
if Respuesta <> IDCANCEL then
|
|||
|
|
begin
|
|||
|
|
case JsPrevisualizarDialog.CustomButtonResult of
|
|||
|
|
200 : begin // Lista de elementos visibles
|
|||
|
|
inherited;
|
|||
|
|
end;
|
|||
|
|
100 : begin // Elemento Seleccionado
|
|||
|
|
if AllItems then
|
|||
|
|
begin
|
|||
|
|
SeleccionarFilasDesdeGrid(ViewGrid._FocusedView, (Facturas as ISeleccionable).SelectedRecords);
|
|||
|
|
AFacturas := (Controller as IFacturasProveedorController).ExtraerSeleccionados(Facturas) as IBizFacturaProveedor;
|
|||
|
|
end
|
|||
|
|
else
|
|||
|
|
AFacturas := Facturas;
|
|||
|
|
|
|||
|
|
if Assigned(AFacturas) then
|
|||
|
|
FController.Preview(AFacturas, AllItems);
|
|||
|
|
end;
|
|||
|
|
end;
|
|||
|
|
end;
|
|||
|
|
end;
|
|||
|
|
}
|
|||
|
|
end;
|
|||
|
|
|
|||
|
|
procedure TfEditorFacturasProveedor.RefrescarInterno;
|
|||
|
|
begin
|
|||
|
|
//Volvemos a cargar los años de las facturas
|
|||
|
|
if Assigned(FController) then
|
|||
|
|
ListaAnos := FController.DarListaAnosFacturas;
|
|||
|
|
|
|||
|
|
inherited;
|
|||
|
|
end;
|
|||
|
|
|
|||
|
|
procedure TfEditorFacturasProveedor.SetController(const Value: IFacturasProveedorController);
|
|||
|
|
begin
|
|||
|
|
FController := Value;
|
|||
|
|
|
|||
|
|
if Assigned(FController) then
|
|||
|
|
ListaAnos := FController.DarListaAnosFacturas;
|
|||
|
|
end;
|
|||
|
|
|
|||
|
|
procedure TfEditorFacturasProveedor.SetFacturas(const Value: IBizFacturaProveedor);
|
|||
|
|
begin
|
|||
|
|
FFacturas := Value;
|
|||
|
|
|
|||
|
|
if Assigned(FFacturas) then
|
|||
|
|
begin
|
|||
|
|
//Se guarda el where de la sentencia origen, por si el editor tiene filtros que
|
|||
|
|
//afecten a este where y en un futuro se desea volver al where origen (filtro de año))
|
|||
|
|
DynWhereDataTable := FFacturas.DataTable.DynamicWhere.Xml;
|
|||
|
|
|
|||
|
|
dsDataTable.DataTable := FFacturas.DataTable;
|
|||
|
|
if Assigned(ViewGrid) then
|
|||
|
|
(ViewGrid as IViewFacturasProveedor).Facturas := Facturas;
|
|||
|
|
end;
|
|||
|
|
end;
|
|||
|
|
|
|||
|
|
end.
|
|||
|
|
|