git-svn-id: https://192.168.0.254/svn/Proyectos.LuisLeon_FactuGES2/trunk@78 b2cfbe5a-eba1-4a0c-8b32-7feea0a119f2
542 lines
16 KiB
ObjectPascal
542 lines
16 KiB
ObjectPascal
unit uEditorPedidosCliente;
|
|
|
|
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,
|
|
uBizPedidosCliente, uIEditorPedidosCliente, uPedidosClienteController,
|
|
uCustomView, uViewBase, uViewBarraSeleccion, uViewGridBase,
|
|
uViewPedidosCliente, JvExComCtrls, JvStatusBar, JSDialog, uDAInterfaces;
|
|
|
|
type
|
|
TfEditorPedidosCliente = class(TfEditorGridBase, IEditorPedidosCliente)
|
|
N4: TMenuItem;
|
|
Cambiarsituacin1: TMenuItem;
|
|
JsNuevoPedidoProveedorDialog: TJSDialog;
|
|
JsPrevisualizarDialog: TJSDialog;
|
|
JsImprimirDialog: TJSDialog;
|
|
TBXItem39: TTBXItem;
|
|
JsListaPedidosNoEliminados: TJSDialog;
|
|
actFacturarPedido: TAction;
|
|
TBXItem38: TTBXItem;
|
|
actEnviarEMail: TAction;
|
|
TBXItem40: TTBXItem;
|
|
Acercade1: TMenuItem;
|
|
actInformes: TAction;
|
|
TBXItem41: TTBXItem;
|
|
JSInformesDialog: TJSDialog;
|
|
JsGenerarDialog: TJSDialog;
|
|
frViewPedidosCliente1: TfrViewPedidosCliente;
|
|
actGenerar: TAction;
|
|
actGenerarAlbaranCli: TAction;
|
|
actGenerarPedidoProv: TAction;
|
|
procedure FormShow(Sender: TObject);
|
|
procedure actCambiarSituacionExecute(Sender: TObject);
|
|
procedure actRecibirPedidoUpdate(Sender: TObject);
|
|
procedure actRecibirPedidoExecute(Sender: TObject);
|
|
procedure actEliminarUpdate(Sender: TObject);
|
|
procedure actFacturarPedidoExecute(Sender: TObject);
|
|
procedure actFacturarPedidoUpdate(Sender: TObject);
|
|
procedure actEnviarEMailExecute(Sender: TObject);
|
|
procedure actEnviarEMailUpdate(Sender: TObject);
|
|
procedure actInformesExecute(Sender: TObject);
|
|
procedure OnListaAnosChange(Sender: TObject; const Text: string);
|
|
procedure actGenerarExecute(Sender: TObject);
|
|
procedure actGenerarUpdate(Sender: TObject);
|
|
procedure actGenerarAlbaranCliExecute(Sender: TObject);
|
|
procedure actGenerarPedidoProvExecute(Sender: TObject);
|
|
|
|
protected
|
|
FPedidos: IBizPedidoCliente;
|
|
FController : IPedidosClienteController;
|
|
|
|
function GetPedidos: IBizPedidoCliente;
|
|
procedure SetPedidos(const Value: IBizPedidoCliente);
|
|
|
|
function GetController : IPedidosClienteController; virtual;
|
|
procedure SetController (const Value : IPedidosClienteController); virtual;
|
|
|
|
procedure NuevoInterno; override;
|
|
procedure ModificarInterno; override;
|
|
procedure EliminarInterno; override;
|
|
procedure DuplicarInterno; override;
|
|
procedure ImprimirInterno; override;
|
|
procedure PrevisualizarInterno; override;
|
|
procedure RefrescarInterno; override;
|
|
|
|
public
|
|
procedure PonerTitulos(const ATitulo: string = ''); override;
|
|
|
|
property Pedidos: IBizPedidoCliente read GetPedidos write SetPedidos;
|
|
property Controller : IPedidosClienteController read GetController write SetController;
|
|
constructor Create(AOwner: TComponent); override;
|
|
destructor Destroy; override;
|
|
end;
|
|
|
|
implementation
|
|
|
|
uses
|
|
uDataModulePedidosCliente, uDataModuleUsuarios, uFactuGES_App, uEditorDBBase,
|
|
// uGenerarFacturasProvPedUtils,
|
|
// uInventarioController, uBizInventario,
|
|
uDialogUtils, uGridStatusUtils, uDBSelectionListUtils, cxControls,
|
|
uDialogOpcionesImpresionPedidosCliente, uGestorInformesController,
|
|
// uAlbaranesProveedorController, uBizAlbaranesProveedor,
|
|
uGenerarAlbaranesCliUtils, uGenerarPedidosProvUtils;
|
|
|
|
{$R *.dfm}
|
|
|
|
{
|
|
*************************** TfEditorPedidosCliente ***************************
|
|
}
|
|
procedure TfEditorPedidosCliente.actCambiarSituacionExecute(Sender: TObject);
|
|
begin
|
|
{
|
|
inherited;
|
|
FController.CambiarSituacion(FPedidos)
|
|
}
|
|
end;
|
|
|
|
procedure TfEditorPedidosCliente.actEliminarUpdate(Sender: TObject);
|
|
begin
|
|
inherited;
|
|
if (Sender as TAction).Enabled then
|
|
(Sender as TAction).Enabled := (FPedidos.SITUACION = SITUACION_PEDIDO_PENDIENTE);
|
|
end;
|
|
|
|
procedure TfEditorPedidosCliente.actEnviarEMailExecute(Sender: TObject);
|
|
var
|
|
APedidos : IBizPedidoCliente;
|
|
begin
|
|
inherited;
|
|
|
|
if ViewGrid.NumSeleccionados = 1 then
|
|
FController.GenerarEmailPedido(Pedidos)
|
|
else begin
|
|
ShowHourglassCursor;
|
|
try
|
|
SeleccionarFilasDesdeGrid(ViewGrid._FocusedView, (Pedidos as ISeleccionable).SelectedRecords);
|
|
APedidos := (Controller as IPedidosClienteController).ExtraerSeleccionados(Pedidos) as IBizPedidoCliente;
|
|
|
|
if Assigned(APedidos) then
|
|
if FController.EnviarEmailPedidos(APedidos) then
|
|
RefrescarInterno;
|
|
finally
|
|
APedidos := NIL;
|
|
HideHourglassCursor;
|
|
end;
|
|
end;
|
|
end;
|
|
|
|
procedure TfEditorPedidosCliente.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 TfEditorPedidosCliente.actFacturarPedidoExecute(Sender: TObject);
|
|
begin
|
|
inherited;
|
|
{
|
|
if (ShowConfirmMessage('Generar factura', Format('¿Desea copiar todos los conceptos del pedido %s a la factura?', [Pedidos.REFERENCIA])) = IDYES) then
|
|
GenerarFacturaProvPed(Pedidos.ID)
|
|
else
|
|
GenerarFacturaProvPed(Pedidos.ID, False);
|
|
|
|
actRefrescar.Execute;
|
|
}
|
|
end;
|
|
|
|
procedure TfEditorPedidosCliente.actFacturarPedidoUpdate(Sender: TObject);
|
|
begin
|
|
inherited;
|
|
(Sender as TAction).Enabled := HayDatos
|
|
and not (ViewGrid.NumSeleccionados > 1)
|
|
// and (FPedidos.REF_FACTURA_PROV = '')
|
|
and ViewGrid.esSeleccionCeldaDatos;
|
|
end;
|
|
|
|
procedure TfEditorPedidosCliente.actGenerarAlbaranCliExecute(Sender: TObject);
|
|
var
|
|
IDAlbaranAux : Integer;
|
|
begin
|
|
inherited;
|
|
GenerarAlbaranCli(FPedidos.ID, IDAlbaranAux);
|
|
end;
|
|
|
|
procedure TfEditorPedidosCliente.actGenerarExecute(Sender: TObject);
|
|
var
|
|
Respuesta : Integer;
|
|
|
|
begin
|
|
inherited;
|
|
|
|
Respuesta := JsGenerarDialog.Execute;
|
|
|
|
if Respuesta <> IDCANCEL then
|
|
begin
|
|
case JsGenerarDialog.CustomButtonResult of
|
|
200 : begin // Generar uno o más pedidos a proveedor
|
|
actGenerarPedidoProv.Execute;
|
|
end;
|
|
100 : begin // Albaran nuevo
|
|
actGenerarAlbaranCli.Execute;
|
|
end;
|
|
end;
|
|
actRefrescar.Execute;
|
|
end;
|
|
|
|
end;
|
|
|
|
procedure TfEditorPedidosCliente.actGenerarPedidoProvExecute(Sender: TObject);
|
|
begin
|
|
inherited;
|
|
GenerarPedidosProv(FPedidos);
|
|
end;
|
|
|
|
procedure TfEditorPedidosCliente.actGenerarUpdate(Sender: TObject);
|
|
begin
|
|
inherited;
|
|
(Sender as TAction).Enabled := HayDatos and
|
|
not (ViewGrid.NumSeleccionados > 1) and
|
|
ViewGrid.esSeleccionCeldaDatos and
|
|
(FPedidos.SITUACION <> SITUACION_PEDIDO_SERVIDO);
|
|
end;
|
|
|
|
procedure TfEditorPedidosCliente.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.VerInformeListadoPedidos;
|
|
end;
|
|
end;
|
|
end;
|
|
|
|
finally
|
|
AGestorInformesController := NIL;
|
|
end;
|
|
end;
|
|
|
|
procedure TfEditorPedidosCliente.actRecibirPedidoExecute(Sender: TObject);
|
|
begin
|
|
inherited;
|
|
// RecibirPedidoProv(FPedidos);
|
|
actRefrescar.Execute;
|
|
end;
|
|
|
|
procedure TfEditorPedidosCliente.actRecibirPedidoUpdate(Sender: TObject);
|
|
begin
|
|
inherited;
|
|
// (Sender as TAction).Enabled := HayDatos and
|
|
// not (ViewGrid.NumSeleccionados > 1) and
|
|
// ViewGrid.esSeleccionCeldaDatos and
|
|
// (FPedidos.SITUACION <> SITUACION_PEDIDO_RECIBIDO);
|
|
end;
|
|
|
|
constructor TfEditorPedidosCliente.Create(AOwner: TComponent);
|
|
begin
|
|
inherited;
|
|
|
|
FHeaderText := 'Lista de pedidos de cliente';
|
|
FWindowCaption := FHeaderText;
|
|
|
|
ViewGrid := frViewPedidosCliente1; //CreateView(TfrViewPedidosCliente) as IViewPedidosCliente;
|
|
end;
|
|
|
|
destructor TfEditorPedidosCliente.Destroy;
|
|
begin
|
|
FPedidos := NIL;
|
|
FController := NIL;
|
|
inherited;
|
|
end;
|
|
|
|
procedure TfEditorPedidosCliente.DuplicarInterno;
|
|
var
|
|
APedido : IBizPedidoCliente;
|
|
begin
|
|
inherited;
|
|
APedido := FController.Duplicar(Pedidos);
|
|
try
|
|
FController.Ver(APedido);
|
|
finally
|
|
actRefrescar.Execute;
|
|
end;
|
|
end;
|
|
|
|
procedure TfEditorPedidosCliente.EliminarInterno;
|
|
var
|
|
APedidos: IBizPedidoCliente;
|
|
AllItems: Boolean;
|
|
begin
|
|
APedidos := Nil;
|
|
AllItems := False;
|
|
|
|
if MultiSelect and Assigned(ViewGrid) then
|
|
AllItems := (ViewGrid.NumSeleccionados > 1);
|
|
|
|
if AllItems then
|
|
begin
|
|
if (Application.MessageBox('¿Desea borrar los pedidos de cliente seleccionados?', 'Atención', MB_YESNO) = IDYES) then
|
|
begin
|
|
SeleccionarFilasDesdeGrid(ViewGrid._FocusedView, (Pedidos as ISeleccionable).SelectedRecords);
|
|
APedidos := (Controller as IPedidosClienteController).ExtraerSeleccionados(Pedidos) as IBizPedidoCliente;
|
|
end
|
|
end
|
|
else begin
|
|
if (Application.MessageBox('¿Desea borrar el pedido de cliente seleccionado?', 'Atención', MB_YESNO) = IDYES) then
|
|
APedidos := Pedidos;
|
|
end;
|
|
|
|
if Assigned(APedidos) then
|
|
begin
|
|
FController.Eliminar(APedidos, AllItems);
|
|
if AllItems then
|
|
begin
|
|
if (APedidos.DataTable.RecordCount > 0) then
|
|
begin
|
|
with APedidos.DataTable do
|
|
begin
|
|
First;
|
|
while not EOF do
|
|
begin
|
|
JsListaPedidosNoEliminados.Content.Add('Ref. pedido: ' + APedidos.REFERENCIA + ' ' + APedidos.NOMBRE);
|
|
Next;
|
|
end;
|
|
end;
|
|
JsListaPedidosNoEliminados.Execute;
|
|
end;
|
|
actRefrescar.Execute;
|
|
end;
|
|
end;
|
|
|
|
ViewGrid.GotoFirst;
|
|
end;
|
|
|
|
procedure TfEditorPedidosCliente.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(Pedidos) then
|
|
raise Exception.Create('No hay ningún pedido asignado');
|
|
|
|
Pedidos.DataTable.Active := True;
|
|
ViewGrid.GotoFirst;
|
|
end;
|
|
|
|
function TfEditorPedidosCliente.GetController: IPedidosClienteController;
|
|
begin
|
|
Result := FController;
|
|
end;
|
|
|
|
function TfEditorPedidosCliente.GetPedidos: IBizPedidoCliente;
|
|
begin
|
|
Result := FPedidos;
|
|
end;
|
|
|
|
procedure TfEditorPedidosCliente.ImprimirInterno;
|
|
var
|
|
Respuesta : Integer;
|
|
APedidos: IBizPedidoCliente;
|
|
AllItems: Boolean;
|
|
FImprimirPrecios : Boolean;
|
|
FImprimirRefProveedor : Boolean;
|
|
begin
|
|
APedidos := Nil;
|
|
AllItems := False;
|
|
FImprimirPrecios := True;
|
|
FImprimirRefProveedor := 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, (Pedidos as ISeleccionable).SelectedRecords);
|
|
APedidos := (Controller as IPedidosClienteController).ExtraerSeleccionados(Pedidos) as IBizPedidoCliente;
|
|
end
|
|
else
|
|
APedidos := Pedidos;
|
|
|
|
if Assigned(APedidos) then
|
|
if ElegirOpcionesImpresionPedidoCliente(FImprimirPrecios, FImprimirRefProveedor) then
|
|
if FController.Print(APedidos, AllItems, FImprimirPrecios, FImprimirRefProveedor) then
|
|
RefrescarInterno;
|
|
end;
|
|
end;
|
|
end;
|
|
end;
|
|
end;
|
|
|
|
procedure TfEditorPedidosCliente.ModificarInterno;
|
|
begin
|
|
inherited;
|
|
FController.Ver(Pedidos);
|
|
end;
|
|
|
|
procedure TfEditorPedidosCliente.NuevoInterno;
|
|
{var
|
|
Respuesta : Integer;}
|
|
|
|
begin
|
|
inherited;
|
|
|
|
// Para Tecsitel: No preguntar si hacer el pedido de proveedor
|
|
// basado en pedido de cliente.
|
|
|
|
{ Respuesta := JsNuevoPedidoClienteDialog.Execute;
|
|
if Respuesta <> IDCANCEL then
|
|
begin
|
|
case JsNuevoPedidoClienteDialog.CustomButtonResult of
|
|
200 : begin // Utilizar un pedido
|
|
// GenerarPedidosProv;
|
|
actRefrescar.Execute;
|
|
end;
|
|
100 : begin // Pedido nuevo vacio
|
|
FController.Anadir(Pedidos);
|
|
FController.Ver(Pedidos);
|
|
end;
|
|
end;
|
|
end;}
|
|
|
|
// Pedido nuevo vacio
|
|
FController.Anadir(Pedidos);
|
|
FController.Ver(Pedidos);
|
|
end;
|
|
|
|
procedure TfEditorPedidosCliente.OnListaAnosChange(Sender: TObject; const Text: string);
|
|
begin
|
|
Controller.FiltrarAno(Pedidos, DynWhereDataTable, Text);
|
|
if Pedidos.DataTable.Active then
|
|
RefrescarInterno;
|
|
end;
|
|
|
|
procedure TfEditorPedidosCliente.PonerTitulos(const ATitulo: string);
|
|
var
|
|
FTitulo : String;
|
|
begin
|
|
FTitulo := FWindowCaption + ' - ' + AppFactuGES.EmpresaActiva.NOMBRE;
|
|
inherited PonerTitulos(FTitulo);
|
|
end;
|
|
|
|
procedure TfEditorPedidosCliente.PrevisualizarInterno;
|
|
var
|
|
Respuesta : Integer;
|
|
APedidos: IBizPedidoCliente;
|
|
AllItems: Boolean;
|
|
FImprimirPrecios : Boolean;
|
|
FImprimirRefProveedor : Boolean;
|
|
begin
|
|
APedidos := Nil;
|
|
AllItems := False;
|
|
FImprimirPrecios := True;
|
|
FImprimirRefProveedor := 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, (Pedidos as ISeleccionable).SelectedRecords);
|
|
APedidos := (Controller as IPedidosClienteController).ExtraerSeleccionados(Pedidos) as IBizPedidoCliente;
|
|
end
|
|
else
|
|
APedidos := Pedidos;
|
|
|
|
if Assigned(APedidos) then
|
|
begin
|
|
if ElegirOpcionesImpresionPedidoCliente(FImprimirPrecios, FImprimirRefProveedor) then
|
|
FController.Preview(APedidos, AllItems, FImprimirPrecios, FImprimirRefProveedor);
|
|
end;
|
|
end;
|
|
end;
|
|
end;
|
|
end;
|
|
end;
|
|
|
|
procedure TfEditorPedidosCliente.RefrescarInterno;
|
|
begin
|
|
//Volvemos a cargar los años de los albaranes
|
|
if Assigned(FController) then
|
|
ListaAnos := FController.DarListaAnosPedidos;
|
|
|
|
inherited;
|
|
end;
|
|
|
|
procedure TfEditorPedidosCliente.SetController(const Value: IPedidosClienteController);
|
|
begin
|
|
FController := Value;
|
|
|
|
if Assigned(FController) then
|
|
ListaAnos := FController.DarListaAnosPedidos;
|
|
end;
|
|
|
|
procedure TfEditorPedidosCliente.SetPedidos(const Value: IBizPedidoCliente);
|
|
begin
|
|
FPedidos := Value;
|
|
|
|
if Assigned(FPedidos) 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 := FPedidos.DataTable.DynamicWhere.Xml;
|
|
|
|
dsDataTable.DataTable := FPedidos.DataTable;
|
|
if Assigned(ViewGrid) then
|
|
(ViewGrid as IViewPedidosCliente).Pedidos := Pedidos;
|
|
end;
|
|
end;
|
|
|
|
end.
|