This repository has been archived on 2024-11-28. You can view files and clone it, but cannot push or open issues or pull requests.
LuisLeon_FactuGES2/Source/Modulos/Facturas proforma/Views/uEditorFacturasProforma.pas

491 lines
15 KiB
ObjectPascal

unit uEditorFacturasProforma;
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,
uBizFacturasProforma, uIEditorFacturasProforma, uFacturasProformaController,
uCustomView, uViewBase, uViewBarraSeleccion, uViewGridBase,
uViewFacturasProforma, JvExComCtrls, JvStatusBar, JSDialog, uDAInterfaces,
cxStyles, cxCustomData,
cxGraphics, cxFilter, cxData, cxDataStorage, cxEdit, cxDBData, cxGridLevel,
cxClasses, cxControls, cxGridCustomView, cxGridCustomTableView,
cxGridTableView, cxGridDBTableView, cxGrid, StdCtrls, cxContainer, cxTextEdit,
cxMaskEdit, cxDropDownEdit, cxLookupEdit, cxDBLookupEdit, cxDBLookupComboBox;
type
TfEditorFacturasProforma = class(TfEditorGridBase, IEditorFacturasProforma)
Cambiarlasituacin1: TMenuItem;
N4: TMenuItem;
JsNuevaFacturaDialog: TJSDialog;
JsListaFacturasGeneradas: TJSDialog;
JsPrevisualizarDialog: TJSDialog;
JsImprimirDialog: TJSDialog;
actNuevaFactura: TAction;
JsNuevoAbonoDialog: TJSDialog;
JsListaFacturasNoEliminadas: TJSDialog;
actEnviarEMail: TAction;
TBXItem40: TTBXItem;
Enviarporemail1: TMenuItem;
JSInformesDialog: TJSDialog;
frViewFacturasProforma1: TfrViewFacturasProforma;
actGenerarFactura: TAction;
TBXItem38: TTBXItem;
actPagada: TAction;
TBXItem39: TTBXItem;
procedure FormShow(Sender: TObject);
procedure actEliminarUpdate(Sender: TObject);
procedure actNuevaFacturaExecute(Sender: TObject);
procedure actEnviarEMailUpdate(Sender: TObject);
procedure actEnviarEMailExecute(Sender: TObject);
procedure OnListaAnosChange(Sender: TObject; const Text: string);
procedure actGenerarFacturaExecute(Sender: TObject);
procedure actGenerarFacturaUpdate(Sender: TObject);
procedure actPagadaUpdate(Sender: TObject);
procedure actPagadaExecute(Sender: TObject);
private
FFacturas: IBizFacturaProforma;
FController : IFacturasProformaController;
protected
function GetFacturas: IBizFacturaProforma;
procedure SetFacturas(const Value: IBizFacturaProforma);
function GetController : IFacturasProformaController; virtual;
procedure SetController (const Value : IFacturasProformaController); virtual;
procedure NuevoInterno; override;
procedure EliminarInterno; override;
procedure ModificarInterno; override;
procedure DuplicarInterno; override;
procedure ImprimirInterno; override;
procedure PrevisualizarInterno; override;
procedure RefrescarInterno; override;
public
property Facturas: IBizFacturaProforma read GetFacturas write SetFacturas;
property Controller : IFacturasProformaController read GetController write SetController;
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;
procedure PonerTitulos(const ATitulo: string = ''); override;
end;
implementation
uses
uDataModuleFacturasProforma, uDataModuleUsuarios, uFactuGES_App,
// uAlbaranesClienteController, //uGenerarFacturasCliPreCliUtils,
// uBizAlbaranesCliente, uGestorInformesController,
uDialogOpcionesImpresionFacturasProforma, uEditorBase, uGridStatusUtils,
uDBSelectionListUtils, udialogUtils, uGenerarFacturasCliFacProformaUtils;
{$R *.dfm}
{
*************************** TfEditorFacturasProforma ***************************
}
procedure TfEditorFacturasProforma.actEliminarUpdate(Sender: TObject);
begin
inherited;
if (Sender as TAction).Enabled then
(Sender as TAction).Enabled := (FFacturas.SITUACION = 'PENDIENTE');
end;
procedure TfEditorFacturasProforma.actEnviarEMailExecute(Sender: TObject);
var
AFacturas : IBizFacturaProforma;
begin
inherited;
if ViewGrid.NumSeleccionados = 1 then
FController.GenerarEmailFactura(FFacturas)
else begin
ShowHourglassCursor;
try
SeleccionarFilasDesdeGrid(ViewGrid._FocusedView, (Facturas as ISeleccionable).SelectedRecords);
AFacturas := (Controller as IFacturasProformaController).ExtraerSeleccionados(Facturas) as IBizFacturaProforma;
if Assigned(AFacturas) then
if FController.EnviarEmailFacturas(AFacturas) then
RefrescarInterno;
finally
AFacturas := NIL;
HideHourglassCursor;
end;
end;
end;
procedure TfEditorFacturasProforma.actEnviarEMailUpdate(Sender: TObject);
begin
inherited;
if HayDatos and Assigned(ViewGrid) then
(Sender as TAction).Enabled := ViewGrid.esSeleccionCeldaDatos
and (ViewGrid.NumSeleccionados > 0)
else
(Sender as TAction).Enabled := False;
end;
procedure TfEditorFacturasProforma.actGenerarFacturaExecute(Sender: TObject);
begin
GenerarFacturaCliFacProforma(Facturas.ID);
actRefrescar.Execute;
end;
procedure TfEditorFacturasProforma.actGenerarFacturaUpdate(Sender: TObject);
begin
inherited;
(Sender as TAction).Enabled := HayDatos and
not (ViewGrid.NumSeleccionados > 1) and
ViewGrid.esSeleccionCeldaDatos;
// and ((FFacturas.ID_FACTURA_FINAL = 0));
end;
procedure TfEditorFacturasProforma.actNuevaFacturaExecute(Sender: TObject);
begin
actNuevo.Execute;
end;
procedure TfEditorFacturasProforma.actPagadaExecute(Sender: TObject);
var
AFacturas: IBizFacturaProforma;
AllItems: Boolean;
AFecha: Variant;
begin
AFacturas := Nil;
AllItems := False;
if MultiSelect and Assigned(ViewGrid) then
AllItems := (ViewGrid.NumSeleccionados > 1);
if AllItems then
begin
SeleccionarFilasDesdeGrid(ViewGrid._FocusedView, (Facturas as ISeleccionable).SelectedRecords);
AFacturas := (Controller as IFacturasProformaController).ExtraerSeleccionados(Facturas) as IBizFacturaProforma;
end
else begin
AFacturas := Facturas;
end;
ViewGrid._Grid.BeginUpdate;
if Assigned(AFacturas) then
begin
FController.CambiarSituacion(AFacturas, CTE_PAGADA, AllItems);
actRefrescar.Execute;
end;
ViewGrid._Grid.EndUpdate;
end;
procedure TfEditorFacturasProforma.actPagadaUpdate(Sender: TObject);
begin
inherited;
(Sender as TAction).Enabled := HayDatos
and ViewGrid.esSeleccionCeldaDatos
and (FFacturas.SITUACION = CTE_PENDIENTE);
end;
constructor TfEditorFacturasProforma.Create(AOwner: TComponent);
begin
inherited;
FHeaderText := 'Lista de facturas proforma';
FWindowCaption := FHeaderText;
ViewGrid := frViewFacturasProforma1;
end;
destructor TfEditorFacturasProforma.Destroy;
begin
FFacturas := NIL;
inherited;
end;
procedure TfEditorFacturasProforma.DuplicarInterno;
var
AFactura : IBizFacturaProforma;
begin
inherited;
AFactura := FController.Duplicar(FFacturas);
try
FController.Ver(AFactura);
finally
actRefrescar.Execute;
end;
end;
procedure TfEditorFacturasProforma.EliminarInterno;
var
ACadena : String;
AFacturas: IBizFacturaProforma;
AllItems: Boolean;
begin
AFacturas := Nil;
AllItems := False;
if MultiSelect and Assigned(ViewGrid) then
AllItems := (ViewGrid.NumSeleccionados > 1);
if AllItems then
begin
if (Application.MessageBox('¿Desea borrar las facturas proforma seleccionadas?', 'Atención', MB_YESNO) = IDYES) then
begin
SeleccionarFilasDesdeGrid(ViewGrid._FocusedView, (Facturas as ISeleccionable).SelectedRecords);
AFacturas := (Controller as IFacturasProformaController).ExtraerSeleccionados(Facturas) as IBizFacturaProforma;
end
end
else begin
if (Application.MessageBox('¿Desea borrar esta factura proforma?', 'Atención', MB_YESNO) = IDYES) then
AFacturas := Facturas;
end;
if Assigned(AFacturas) then
begin
if (not FController.Eliminar(AFacturas, AllItems))
and (not AllItems) then //Es el caso de querer borrar una factura pendiente cuyos recibos tienen devoluciones
begin
JsListaFacturasNoEliminadas.Content.Clear;
JsListaFacturasNoEliminadas.Content.Add('Ref. factura: ' + AFacturas.REFERENCIA + ' ' + AFacturas.NOMBRE);
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);
Next;
end;
end;
JsListaFacturasNoEliminadas.Execute;
end;
actRefrescar.Execute;
end
end;
ViewGrid.GotoFirst;
end;
procedure TfEditorFacturasProforma.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 factura asignada');
Facturas.DataTable.Active := True;
ViewGrid.GotoFirst;
end;
function TfEditorFacturasProforma.GetController: IFacturasProformaController;
begin
Result := FController;
end;
function TfEditorFacturasProforma.GetFacturas: IBizFacturaProforma;
begin
Result := FFacturas;
end;
procedure TfEditorFacturasProforma.ImprimirInterno;
var
Respuesta : Integer;
AFacturas: IBizFacturaProforma;
AllItems: Boolean;
AVerSello: Boolean;
AVerCopia: Boolean;
begin
AFacturas := Nil;
AllItems := False;
AVerSello := True;
AVerCopia := True;
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 IFacturasProformaController).ExtraerSeleccionados(Facturas) as IBizFacturaProforma;
end
else
AFacturas := Facturas;
//Preguntamos si desea que en las facturas se vea el Sello
// if ElegirOpcionesImpresionFacturaProforma(AVerSello, AVerCopia) then
if Assigned(AFacturas) then
if FController.Print(AFacturas, AllItems, AVerSello, AVerCopia) then
RefrescarInterno;
end;
end;
end;
end;
end;
procedure TfEditorFacturasProforma.ModificarInterno;
begin
inherited;
FController.Ver(Facturas);
end;
procedure TfEditorFacturasProforma.NuevoInterno;
var
Respuesta : Integer;
begin
inherited;
{
Respuesta := JsNuevaFacturaDialog.Execute;
if Respuesta <> IDCANCEL then
begin
case JsNuevaFacturaDialog.CustomButtonResult of
200 : begin // Utilizar presupuestos
// GenerarFacturaCliPre;
actRefrescar.Execute;
end;
300 : begin // Utilizar albaranes
// GenerarFacturaCliAlb;
actRefrescar.Execute;
end;
100 : begin // Albaran nuevo vacio
}
if FController.Anadir(Facturas) then
FController.Ver(Facturas);
{
end;
end;
end;
}
end;
procedure TfEditorFacturasProforma.OnListaAnosChange(Sender: TObject; const Text: string);
begin
Controller.FiltrarAno(Facturas, DynWhereDataTable, Text);
if Facturas.DataTable.Active then
RefrescarInterno;
end;
procedure TfEditorFacturasProforma.PonerTitulos(const ATitulo: string);
var
FTitulo : String;
begin
FTitulo := FWindowCaption + ' - ' + AppFactuGES.EmpresaActiva.NOMBRE;
inherited PonerTitulos(FTitulo);
end;
procedure TfEditorFacturasProforma.PrevisualizarInterno;
var
Respuesta : Integer;
AFacturas: IBizFacturaProforma;
AllItems: Boolean;
AVerSello: Boolean;
AVerCopia: Boolean;
begin
AFacturas := Nil;
AllItems := False;
AVerSello := True;
AVerCopia := True;
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 IFacturasProformaController).ExtraerSeleccionados(Facturas) as IBizFacturaProforma;
end
else
AFacturas := Facturas;
//Preguntamos si desea que en las facturas se vea el Sello
// if ElegirOpcionesImpresionFacturaProforma(AVerSello, AVerCopia) then
if Assigned(AFacturas) then
FController.Preview(AFacturas, AllItems, AVerSello, AVerCopia);
end;
end;
end;
end;
end;
procedure TfEditorFacturasProforma.RefrescarInterno;
begin
//Volvemos a cargar los años de las facturas
if Assigned(FController) then
ListaAnos := FController.DarListaAnosFacturas;
inherited;
end;
procedure TfEditorFacturasProforma.SetController(const Value: IFacturasProformaController);
begin
FController := Value;
if Assigned(FController) then
ListaAnos := FController.DarListaAnosFacturas;
end;
procedure TfEditorFacturasProforma.SetFacturas(const Value: IBizFacturaProforma);
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 IViewFacturasProforma).Facturas := Facturas;
end;
end;
end.