git-svn-id: https://192.168.0.254/svn/Proyectos.Noviseda_FactuGES2/trunk@124 f33bb606-9f5c-448d-9c99-757f00063c96
355 lines
11 KiB
ObjectPascal
355 lines
11 KiB
ObjectPascal
unit uEditorComisiones;
|
|
|
|
interface
|
|
|
|
uses
|
|
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
|
|
Dialogs, Menus, DB, uDADataTable, JvAppStorage,
|
|
JvAppRegistryStorage, JvComponent, JvFormPlacement, ImgList,
|
|
PngImageList, StdActns, ActnList, ComCtrls, TB2ExtItems,
|
|
SpTBXItem, TB2Item, TB2Dock, TB2Toolbar, ExtCtrls, JvExControls,
|
|
JvNavigationPane, uViewGrid, pngimage, JvComponentBase,
|
|
uEditorGridBase,
|
|
uBizComisiones, uIEditorComisiones, uComisionesController,
|
|
uCustomView, uViewBase, uViewBarraSeleccion, uViewGridBase,
|
|
uViewComisiones, 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,
|
|
TntStdCtrls, SpTBXEditors;
|
|
|
|
type
|
|
|
|
TfEditorComisiones = class(TfEditorGridBase, IEditorComisiones)
|
|
JsNuevaComisionDialog: TJSDialog;
|
|
JsListaComisionesGeneradas: TJSDialog;
|
|
JsPrevisualizarDialog: TJSDialog;
|
|
JsImprimirDialog: TJSDialog;
|
|
JsListaComisionesNoEliminadas: TJSDialog;
|
|
actEnviarEMail: TAction;
|
|
TBXItem40: TSpTBXItem;
|
|
Enviarporemail1: TMenuItem;
|
|
TBXItem41: TSpTBXItem;
|
|
JSInformesDialog: TJSDialog;
|
|
frViewComisiones1: TfrViewComisiones;
|
|
procedure FormShow(Sender: TObject);
|
|
procedure actEnviarEMailUpdate(Sender: TObject);
|
|
procedure actEnviarEMailExecute(Sender: TObject);
|
|
procedure OnListaAnosChange(Sender: TObject);
|
|
|
|
private
|
|
FComisiones: IBizComision;
|
|
FController : IComisionesController;
|
|
|
|
protected
|
|
function GetComisiones: IBizComision;
|
|
procedure SetComisiones(const Value: IBizComision);
|
|
|
|
function GetController : IComisionesController; virtual;
|
|
procedure SetController (const Value : IComisionesController); virtual;
|
|
|
|
procedure NuevoInterno; override;
|
|
procedure EliminarInterno; override;
|
|
procedure ModificarInterno; override;
|
|
procedure ImprimirInterno; override;
|
|
procedure PrevisualizarInterno; override;
|
|
procedure RefrescarInterno; override;
|
|
|
|
public
|
|
property Comisiones: IBizComision read GetComisiones write SetComisiones;
|
|
property Controller : IComisionesController read GetController write SetController;
|
|
constructor Create(AOwner: TComponent); override;
|
|
destructor Destroy; override;
|
|
procedure PonerTitulos(const ATitulo: string = ''); override;
|
|
end;
|
|
|
|
|
|
implementation
|
|
|
|
uses
|
|
uDataModuleComisiones, uDataModuleUsuarios, uFactuGES_App,
|
|
uEditorBase, uGridStatusUtils, uDBSelectionListUtils, udialogUtils;
|
|
|
|
{$R *.dfm}
|
|
|
|
{
|
|
*************************** TfEditorComisionesCliente ***************************
|
|
}
|
|
procedure TfEditorComisiones.actEnviarEMailExecute(Sender: TObject);
|
|
begin
|
|
inherited;
|
|
// FController.EnviarComisionPorEMail(FComisiones);
|
|
end;
|
|
|
|
procedure TfEditorComisiones.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;
|
|
|
|
constructor TfEditorComisiones.Create(AOwner: TComponent);
|
|
begin
|
|
inherited;
|
|
|
|
FHeaderText := 'Lista de comisiones';
|
|
FWindowCaption := FHeaderText;
|
|
|
|
ViewGrid := frViewComisiones1;
|
|
end;
|
|
|
|
destructor TfEditorComisiones.Destroy;
|
|
begin
|
|
FComisiones := NIL;
|
|
inherited;
|
|
end;
|
|
|
|
procedure TfEditorComisiones.EliminarInterno;
|
|
var
|
|
AComisiones: IBizComision;
|
|
AllItems: Boolean;
|
|
begin
|
|
AComisiones := Nil;
|
|
AllItems := False;
|
|
|
|
if MultiSelect and Assigned(ViewGrid) then
|
|
AllItems := (ViewGrid.NumSeleccionados > 1);
|
|
|
|
if AllItems then
|
|
begin
|
|
if (Application.MessageBox('¿Desea borrar las comisiones de cliente seleccionadas?', 'Atención', MB_YESNO) = IDYES) then
|
|
begin
|
|
SeleccionarFilasDesdeGrid(ViewGrid._FocusedView, (Comisiones as ISeleccionable).SelectedRecords);
|
|
AComisiones := (Controller as IComisionesController).ExtraerSeleccionados(Comisiones) as IBizComision;
|
|
end
|
|
end
|
|
else begin
|
|
if (Application.MessageBox('¿Desea borrar la comisión de cliente seleccionada?', 'Atención', MB_YESNO) = IDYES) then
|
|
AComisiones := Comisiones;
|
|
end;
|
|
|
|
if Assigned(AComisiones) then
|
|
begin
|
|
if (not FController.Eliminar(AComisiones, AllItems))
|
|
and (not AllItems) then //Es el caso de querer borrar una factura pendiente cuyos recibos tienen devoluciones
|
|
begin
|
|
JsListaComisionesNoEliminadas.Content.Clear;
|
|
JsListaComisionesNoEliminadas.Content.Add('Ref. comisión: ' + AComisiones.REFERENCIA + ' ' + AComisiones.DESCRIPCION);
|
|
JsListaComisionesNoEliminadas.Execute;
|
|
end;
|
|
|
|
if AllItems then
|
|
begin
|
|
if (AComisiones.DataTable.RecordCount > 0) then
|
|
begin
|
|
with AComisiones.DataTable do
|
|
begin
|
|
JsListaComisionesNoEliminadas.Content.Clear;
|
|
First;
|
|
while not EOF do
|
|
begin
|
|
JsListaComisionesNoEliminadas.Content.Add('Ref. comisión: ' + AComisiones.REFERENCIA + ' ' + AComisiones.DESCRIPCION);
|
|
Next;
|
|
end;
|
|
end;
|
|
JsListaComisionesNoEliminadas.Execute;
|
|
end;
|
|
actRefrescar.Execute;
|
|
end
|
|
end;
|
|
|
|
ViewGrid.GotoFirst;
|
|
end;
|
|
|
|
procedure TfEditorComisiones.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(Comisiones) then
|
|
raise Exception.Create('No hay ninguna factura asignada');
|
|
|
|
Comisiones.DataTable.Active := True;
|
|
ViewGrid.GotoFirst;
|
|
end;
|
|
|
|
function TfEditorComisiones.GetController: IComisionesController;
|
|
begin
|
|
Result := FController;
|
|
end;
|
|
|
|
function TfEditorComisiones.GetComisiones: IBizComision;
|
|
begin
|
|
Result := FComisiones;
|
|
end;
|
|
|
|
procedure TfEditorComisiones.ImprimirInterno;
|
|
var
|
|
Respuesta : Integer;
|
|
AComisiones: IBizComision;
|
|
AllItems: Boolean;
|
|
AOriginal: Integer;
|
|
ACopia: Integer;
|
|
AContabilidad: Integer;
|
|
|
|
begin
|
|
{
|
|
AComisiones := 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, (Comisiones as ISeleccionable).SelectedRecords);
|
|
AComisiones := (Controller as IComisionesClienteController).ExtraerSeleccionados(Comisiones) as IBizComision;
|
|
end
|
|
else
|
|
AComisiones := Comisiones;
|
|
|
|
//Preguntamos si desea que en las facturas se vea el Sello
|
|
if ElegirOpcionesImpresionFacturaCliente(AOriginal, ACopia, AContabilidad) then
|
|
if Assigned(AComisiones) then
|
|
FController.Print(AComisiones, AOriginal, ACopia, AContabilidad, AllItems);
|
|
end;
|
|
end;
|
|
end;
|
|
end;
|
|
}
|
|
end;
|
|
|
|
procedure TfEditorComisiones.ModificarInterno;
|
|
begin
|
|
inherited;
|
|
FController.Ver(Comisiones);
|
|
end;
|
|
|
|
procedure TfEditorComisiones.NuevoInterno;
|
|
begin
|
|
inherited;
|
|
FController.Anadir(Comisiones);
|
|
FController.Ver(Comisiones);
|
|
end;
|
|
|
|
procedure TfEditorComisiones.OnListaAnosChange(Sender: TObject);
|
|
begin
|
|
Controller.FiltrarAno(Comisiones, DynWhereDataTable, cbxListaAnos.Text);
|
|
if Comisiones.DataTable.Active then
|
|
RefrescarInterno;
|
|
end;
|
|
|
|
procedure TfEditorComisiones.PonerTitulos(const ATitulo: string);
|
|
var
|
|
FTitulo : String;
|
|
begin
|
|
FTitulo := FWindowCaption + ' - ' + AppFactuGES.EmpresaActiva.NOMBRE;
|
|
inherited PonerTitulos(FTitulo);
|
|
end;
|
|
|
|
procedure TfEditorComisiones.PrevisualizarInterno;
|
|
var
|
|
Respuesta : Integer;
|
|
AComisiones: IBizComision;
|
|
AllItems: Boolean;
|
|
AOriginal: Integer;
|
|
ACopia: Integer;
|
|
AContabilidad: Integer;
|
|
|
|
begin
|
|
{
|
|
AComisiones := 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, (Comisiones as ISeleccionable).SelectedRecords);
|
|
AComisiones := (Controller as IComisionesClienteController).ExtraerSeleccionados(Comisiones) as IBizComision;
|
|
end
|
|
else
|
|
AComisiones := Comisiones;
|
|
|
|
//Preguntamos si desea que en las facturas se vea el Sello
|
|
if ElegirOpcionesImpresionFacturaCliente(AOriginal, ACopia, AContabilidad) then
|
|
if Assigned(AComisiones) then
|
|
FController.Preview(AComisiones, AOriginal, ACopia, AContabilidad, AllItems);
|
|
end;
|
|
end;
|
|
end;
|
|
end;
|
|
}
|
|
end;
|
|
|
|
procedure TfEditorComisiones.RefrescarInterno;
|
|
begin
|
|
//Volvemos a cargar los años de las comisiones
|
|
if Assigned(FController) then
|
|
ListaAnos := FController.DarListaAnosComisiones;
|
|
|
|
inherited;
|
|
end;
|
|
|
|
procedure TfEditorComisiones.SetController(const Value: IComisionesController);
|
|
begin
|
|
FController := Value;
|
|
|
|
if Assigned(FController) then
|
|
ListaAnos := FController.DarListaAnosComisiones;
|
|
end;
|
|
|
|
procedure TfEditorComisiones.SetComisiones(const Value: IBizComision);
|
|
begin
|
|
FComisiones := Value;
|
|
|
|
if Assigned(FComisiones) 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 := FComisiones.DataTable.DynamicWhere.Xml;
|
|
|
|
dsDataTable.DataTable := FComisiones.DataTable;
|
|
if Assigned(ViewGrid) then
|
|
(ViewGrid as IViewComisiones).Comisiones := Comisiones;
|
|
end;
|
|
end;
|
|
|
|
end.
|