unit uEditorClientes; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, uEditorContactos, Menus, ImgList, PngImageList, StdActns, ActnList, TB2ExtItems, TBXExtItems, TBX, TB2Item, TB2Dock, TB2Toolbar, JvExControls, JvComponent, JvNavigationPane, DB, uDADataTable, JvFormAutoSize, ComCtrls, uDAScriptingProvider, uDACDSDataTable, StdCtrls, JvAppStorage, JvAppRegistryStorage, JvFormPlacement, uCustomView, uViewBase, uViewBarraSeleccion, ExtCtrls, pngimage, JvComponentBase, uIEditorClientes, uViewGridBase, uViewGrid, uViewContactos, uViewClientes, TBXStatusBars, JvExComCtrls, JvStatusBar, JSDialog, uDAInterfaces; type TfEditorClientes = class(TfEditorContactos, IEditorClientes) JsPrevisualizarDialog: TJSDialog; JsImprimirDialog: TJSDialog; actGruposCliente: TAction; JsListaContactosNoEliminados: TJSDialog; frViewClientes1: TfrViewClientes; actInformes: TAction; TBXItem38: TTBXItem; JSInformesDialog: TJSDialog; actCambiarPrecioPunto: TAction; TBXSeparatorItem17: TTBXSeparatorItem; TBXItem39: TTBXItem; actCambiarComercial: TAction; TBXSeparatorItem18: TTBXSeparatorItem; TBXItem40: TTBXItem; procedure actGruposClienteExecute(Sender: TObject); procedure actInformesExecute(Sender: TObject); procedure actCambiarPrecioPuntoExecute(Sender: TObject); procedure actCambiarPrecioPuntoUpdate(Sender: TObject); procedure actCambiarComercialExecute(Sender: TObject); procedure actCambiarComercialUpdate(Sender: TObject); procedure FormShow(Sender: TObject); protected procedure ImprimirInterno; override; procedure PrevisualizarInterno; override; procedure EliminarInterno; override; public constructor Create(AOwner: TComponent); override; procedure PonerTitulos(const ATitulo: string = ''); override; end; implementation uses uGridUtils, uDataModuleContactos, uDMBase, uEditorGridBase, uBizContactos, uDBSelectionListUtils, uDataModuleUsuarios, uDialogUtils, uFactuGES_App, uGruposClienteController, uBizGruposCliente, uClientesController, uGestorInformesController, uEditorAsignarPrecioPunto, uEditorAsignarComercial, Dialogs; {$R *.dfm} { ******************************* TfEditorClientes ******************************* } procedure TfEditorClientes.actCambiarComercialExecute(Sender: TObject); var AClientes: IBizCliente; AllItems: Boolean; AID_AGENTE: Variant; begin AClientes := Nil; AllItems := False; if MultiSelect and Assigned(ViewGrid) then AllItems := (ViewGrid.NumSeleccionados > 1); if AsignarComercial(AID_AGENTE) then begin if AllItems then begin SeleccionarFilasDesdeGrid(ViewGrid._FocusedView, (Contactos as ISeleccionable).SelectedRecords); AClientes := (Controller as IClientesController).ExtraerSeleccionados(Contactos) as IBizCliente; end else AClientes := (Contactos as IBizCliente); (Controller as IClientesController).AsignarComercial(AClientes, AID_AGENTE, AllItems); actRefrescar.Execute; end; end; procedure TfEditorClientes.actCambiarComercialUpdate(Sender: TObject); begin inherited; // end; procedure TfEditorClientes.actCambiarPrecioPuntoExecute(Sender: TObject); var AClientes: IBizCliente; AllItems: Boolean; APrecioPunto: Variant; begin AClientes := Nil; AllItems := False; if MultiSelect and Assigned(ViewGrid) then AllItems := (ViewGrid.NumSeleccionados > 1); if AsignarPrecioPunto(APrecioPunto) then begin if AllItems then begin SeleccionarFilasDesdeGrid(ViewGrid._FocusedView, (Contactos as ISeleccionable).SelectedRecords); AClientes := (Controller as IClientesController).ExtraerSeleccionados(Contactos) as IBizCliente; end else AClientes := (Contactos as IBizCliente); (Controller as IClientesController).AsignarPrecioPunto(AClientes, APrecioPunto, AllItems); // ShowMessage(APrecioPunto); actRefrescar.Execute; end; end; procedure TfEditorClientes.actCambiarPrecioPuntoUpdate(Sender: TObject); begin inherited; (Sender as TAction).Enabled := HayDatos and ViewGrid.esSeleccionCeldaDatos; end; procedure TfEditorClientes.actGruposClienteExecute(Sender: TObject); var AGruposController : IGruposClienteController; AGrupos : IBizGrupoCliente; begin AGruposController := TGruposClienteController.Create; try AGrupos := (AGruposController.BuscarTodos as IBizGrupoCliente); AGruposController.VerTodos(AGrupos); finally AGrupos := NIL; AGruposController := NIL; end; end; procedure TfEditorClientes.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 400 : begin // Listado de facturas de cliente AGestorInformesController.VerInformeListadoFacturasRecibosCli(Contactos.ID); end; end; end; finally AGestorInformesController := NIL; end; end; constructor TfEditorClientes.Create(AOwner: TComponent); begin inherited; ViewGrid := frViewClientes1; end; procedure TfEditorClientes.EliminarInterno; var AContactos: IBizContacto; AllItems: Boolean; begin AContactos := Nil; AllItems := False; if MultiSelect and Assigned(ViewGrid) then AllItems := (ViewGrid.NumSeleccionados > 1); if AllItems then begin if (Application.MessageBox('¿Desea borrar los clientes seleccionados?', 'Atención', MB_YESNO) = IDYES) then begin SeleccionarFilasDesdeGrid(ViewGrid._FocusedView, (Contactos as ISeleccionable).SelectedRecords); AContactos := (Controller as IClientesController).ExtraerSeleccionados(Contactos) as IBizContacto; end end else begin if (Application.MessageBox('¿Desea borrar el cliente seleccionado?', 'Atención', MB_YESNO) = IDYES) then AContactos := Contactos; end; if Assigned(AContactos) then begin (FController as IClientesController).Eliminar(AContactos, AllItems); if AllItems then begin if (AContactos.DataTable.RecordCount > 0) then begin with AContactos.DataTable do begin First; while not EOF do begin JsListaContactosNoEliminados.Content.Add('Cliente: ' + AContactos.NOMBRE); Next; end; end; JsListaContactosNoEliminados.Execute; end; actRefrescar.Execute; end; end; ViewGrid.GotoFirst; end; procedure TfEditorClientes.FormShow(Sender: TObject); begin inherited; if (AppFactuGES.EmpresaActiva.ID = CTE_EMPRESA_ABETO) then begin actCambiarComercial.Visible := True; end else begin actCambiarComercial.Visible := False; end; end; procedure TfEditorClientes.ImprimirInterno; var Respuesta : Integer; AClientes: IBizCliente; AllItems: Boolean; begin inherited; //Desactivamos la impresion de etiquetas { AClientes := 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, (Contactos as ISeleccionable).SelectedRecords); AClientes := (Controller as IClientesController).ExtraerSeleccionados(Contactos) as IBizCliente; end else AClientes := (Contactos as IBizCliente); if Assigned(AClientes) then (FController as IClientesController).Print(AClientes, AllItems); end; end; end; end; } end; procedure TfEditorClientes.PonerTitulos(const ATitulo: string); var FTitulo : String; begin FTitulo := 'Lista de clientes - ' + AppFactuGES.EmpresaActiva.NOMBRE; inherited PonerTitulos(FTitulo); end; procedure TfEditorClientes.PrevisualizarInterno; var Respuesta : Integer; AClientes: IBizCliente; AllItems: Boolean; begin inherited; //Desactivamos la impresion de etiquetas { AClientes := 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, (Contactos as ISeleccionable).SelectedRecords); AClientes := (Controller as IClientesController).ExtraerSeleccionados(Contactos) as IBizCliente; end else AClientes := (Contactos as IBizCliente); if Assigned(AClientes) then (FController as IClientesController).Preview(AClientes, AllItems); end; end; end; end; } end; end.