git-svn-id: https://192.168.0.254/svn/Proyectos.Noviseda_FactuGES2/trunk@101 f33bb606-9f5c-448d-9c99-757f00063c96
457 lines
13 KiB
ObjectPascal
457 lines
13 KiB
ObjectPascal
unit uEditorPedidosCliente;
|
||
|
||
interface
|
||
|
||
uses
|
||
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
|
||
Menus, DB, uDADataTable, JvAppStorage,
|
||
JvAppRegistryStorage, JvComponent, JvFormPlacement, ImgList,
|
||
PngImageList, StdActns, ActnList, ComCtrls, TB2ExtItems,
|
||
|
||
JvNavigationPane, uViewGrid, pngimage, JvComponentBase,
|
||
uEditorGridBase,
|
||
uBizPedidosCliente, uIEditorPedidosCliente, uPedidosClienteController,
|
||
uCustomView, uViewBase, uViewBarraSeleccion, uViewGridBase,
|
||
uViewPedidosCliente, JvExComCtrls, JvStatusBar, JSDialog, StdCtrls,
|
||
uDAInterfaces, SpTBXItem, TntStdCtrls, SpTBXEditors, TB2Item, TB2Dock,
|
||
TB2Toolbar, ExtCtrls, JvExControls;
|
||
|
||
type
|
||
TfEditorPedidosCliente = class(TfEditorGridBase, IEditorPedidosCliente)
|
||
actGenerarAlbaranCli: TAction;
|
||
actGenerarFactura: TAction;
|
||
actGenerarPedidoProv: TAction;
|
||
N4: TMenuItem;
|
||
actGenerar: TAction;
|
||
Generar2: TMenuItem;
|
||
JsGenerarDialog: TJSDialog;
|
||
JsPrevisualizarDialog: TJSDialog;
|
||
JsImprimirDialog: TJSDialog;
|
||
JsListaPedidosNoEliminados: TJSDialog;
|
||
actEnviarEmail: TAction;
|
||
procedure FormShow(Sender: TObject);
|
||
procedure actGenerarAlbaranCliExecute(Sender: TObject);
|
||
procedure actEliminarUpdate(Sender: TObject);
|
||
procedure actGenerarFacturaUpdate(Sender: TObject);
|
||
procedure actGenerarFacturaExecute(Sender: TObject);
|
||
procedure actGenerarPedidoProvExecute(Sender: TObject);
|
||
procedure actGenerarExecute(Sender: TObject);
|
||
procedure actGenerarUpdate(Sender: TObject);
|
||
procedure actEnviarEmailExecute(Sender: TObject);
|
||
procedure actEnviarEmailUpdate(Sender: TObject);
|
||
procedure OnListaAnosChange(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;
|
||
|
||
//Si queremos crear otra vista para el editor heredado solo tendriamos que
|
||
//sobreescribir este metodo
|
||
procedure AsignarVista; virtual;
|
||
|
||
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, uBizAlbaranesCliente,
|
||
uAlbaranesClienteController, uEditorBase, uEditorDBBase, uDialogUtils,
|
||
uFacturasClienteController, uBizFacturasCliente, uGridUtils, uDBSelectionListUtils,
|
||
// uGenerarPedidosProvUtils,
|
||
uGenerarAlbaranesCliUtils, cxControls, uFactuGES_App;
|
||
|
||
|
||
{$R *.dfm}
|
||
|
||
{
|
||
*************************** TfEditorPedidosCliente ***************************
|
||
}
|
||
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, ViewGrid) 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.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.actGenerarFacturaExecute(Sender: TObject);
|
||
var
|
||
AFacturasController : IFacturasClienteController;
|
||
AFactura : IBizFacturaCliente;
|
||
begin
|
||
inherited;
|
||
{
|
||
AFacturasController := TFacturasClienteController.Create;
|
||
try
|
||
AFactura := AFacturasController.Nuevo;
|
||
if AFacturasController.Anadir(AFactura, FPedidos.ID) then
|
||
AFacturasController.Ver(AFactura);
|
||
actRefrescar.Execute;
|
||
finally
|
||
AFacturasController := NIL;
|
||
AFactura := NIL;
|
||
end;
|
||
}
|
||
end;
|
||
|
||
procedure TfEditorPedidosCliente.actGenerarFacturaUpdate(Sender: TObject);
|
||
begin
|
||
inherited;
|
||
(Sender as TAction).Enabled := HayDatos
|
||
and ViewGrid.esSeleccionCeldaDatos
|
||
and (FPedidos.SITUACION = SITUACION_PEDIDO_PENDIENTE);
|
||
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.AsignarVista;
|
||
begin
|
||
ViewGrid := CreateView(TfrViewPedidosCliente) as IViewPedidosCliente;
|
||
end;
|
||
|
||
constructor TfEditorPedidosCliente.Create(AOwner: TComponent);
|
||
begin
|
||
inherited;
|
||
AsignarVista;
|
||
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('<27>Desea borrar los pedidos de proveedor seleccionados?', 'Atenci<63>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('<27>Desea borrar el pedido de proveedor seleccionado?', 'Atenci<63>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 QUE EL 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<6E>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;
|
||
begin
|
||
APedidos := Nil;
|
||
AllItems := False;
|
||
|
||
if MultiSelect and Assigned(ViewGrid) then
|
||
AllItems := (ViewGrid.NumSeleccionados > 1);
|
||
|
||
//Si esta agrupado solo podr<64> 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 FController.Print(APedidos, AllItems) then
|
||
RefrescarInterno;
|
||
end;
|
||
end;
|
||
end;
|
||
end;
|
||
end;
|
||
|
||
procedure TfEditorPedidosCliente.ModificarInterno;
|
||
begin
|
||
inherited;
|
||
FController.Ver(Pedidos);
|
||
end;
|
||
|
||
procedure TfEditorPedidosCliente.NuevoInterno;
|
||
begin
|
||
inherited;
|
||
if FController.Anadir(Pedidos) then
|
||
FController.Ver(Pedidos);
|
||
end;
|
||
|
||
procedure TfEditorPedidosCliente.OnListaAnosChange(Sender: TObject);
|
||
begin
|
||
Controller.FiltrarAno(Pedidos, DynWhereDataTable, cbxListaAnos.Text);
|
||
if Pedidos.DataTable.Active then
|
||
RefrescarInterno;
|
||
end;
|
||
|
||
procedure TfEditorPedidosCliente.PonerTitulos(const ATitulo: string);
|
||
var
|
||
FTitulo : String;
|
||
begin
|
||
FTitulo := 'Lista de pedidos de cliente - ' + AppFactuGES.EmpresaActiva.NOMBRE;
|
||
inherited PonerTitulos(FTitulo);
|
||
end;
|
||
|
||
procedure TfEditorPedidosCliente.PrevisualizarInterno;
|
||
var
|
||
Respuesta : Integer;
|
||
APedidos: IBizPedidoCliente;
|
||
AllItems: Boolean;
|
||
begin
|
||
APedidos := Nil;
|
||
AllItems := False;
|
||
|
||
if MultiSelect and Assigned(ViewGrid) then
|
||
AllItems := (ViewGrid.NumSeleccionados > 1);
|
||
|
||
//Si esta agrupado solo podr<64> 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
|
||
FController.Preview(APedidos, AllItems);
|
||
end;
|
||
end;
|
||
end;
|
||
end;
|
||
end;
|
||
|
||
procedure TfEditorPedidosCliente.RefrescarInterno;
|
||
begin
|
||
//Volvemos a cargar los a<>os de los pedidos
|
||
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.
|