AbetoDesign_FactuGES2/Source/Modulos/Inventario/Views/uEditorInventario.pas

406 lines
12 KiB
ObjectPascal
Raw Normal View History

unit uEditorInventario;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
uCustomEditor, ImgList, PngImageList, StdActns, ActnList, TB2ExtItems, TBXExtItems, TBX, TB2Item,
TB2Dock, TB2Toolbar, JvExControls, JvComponent, JvNavigationPane,
uViewInventario, Menus, DB, uDADataTable, ComCtrls, uViewGrid,
uDAScriptingProvider, uDACDSDataTable, JvAppStorage,
JvAppRegistryStorage, JvFormPlacement, pngimage, ExtCtrls, uCustomView,
uViewBase, uViewBarraSeleccion, JvComponentBase, uEditorGridBase,
uIEditorInventario, uBizInventario, uViewGridBase, uInventarioController,
JvExComCtrls, JvStatusBar, uViewGrid2Niveles, JSDialog, uBizAlmacenes,
uDAInterfaces;
type
TfEditorInventario = class(TfEditorGridBase, IEditorInventario)
actRecibirPedido: TAction;
actTrasladar: TAction;
actReservar: TAction;
actLiberar: TAction;
TBXSeparatorItem17: TTBXSeparatorItem;
rasladar1: TMenuItem;
Liberar1: TMenuItem;
Reservar1: TMenuItem;
actExpandir: TAction;
actContraer: TAction;
frViewInventario1: TfrViewInventario;
JsElegirAlmacenDialog: TJSDialog;
actReservados: TAction;
TBXItem38: TTBXItem;
actInformes: TAction;
TBXItem39: TTBXItem;
JSInformesDialog: TJSDialog;
procedure actModificarExecute(Sender: TObject);
procedure actRecibirPedidoExecute(Sender: TObject);
procedure actTrasladarExecute(Sender: TObject);
procedure actReservarExecute(Sender: TObject);
procedure actLiberarExecute(Sender: TObject);
procedure actTrasladarUpdate(Sender: TObject);
procedure actReservarUpdate(Sender: TObject);
procedure actLiberarUpdate(Sender: TObject);
procedure actExpandirExecute(Sender: TObject);
procedure actContraerExecute(Sender: TObject);
procedure FormShow(Sender: TObject);
procedure actReservadosUpdate(Sender: TObject);
procedure actReservadosExecute(Sender: TObject);
procedure actInformesExecute(Sender: TObject);
private
function SeleccionarAlmacen(Descripcion: String): Integer;
function DarIDAlmacenSeleccionado(Descripcion: String): Integer;
function GetAlmacenes: IBizAlmacen;
procedure SetAlmacenes (const Value : IBizAlmacen);
protected
FInventario: IBizInventario;
FController : IInventarioController;
function GetInventario: IBizInventario;
procedure SetInventario(const Value: IBizInventario);
function GetController : IInventarioController; virtual;
procedure SetController (const Value : IInventarioController); virtual;
procedure SetMultiSelect (AValue : Boolean);
function GetMultiSelect : Boolean;
function GetArticulosSeleccionados: IBizInventario;
procedure NuevoInterno; override;
procedure EliminarInterno; override;
procedure ImprimirInterno; override;
procedure PrevisualizarInterno; override;
public
property Almacenes: IBizAlmacen read GetAlmacenes write SetAlmacenes;
property Inventario: IBizInventario read GetInventario write SetInventario;
property Controller : IInventarioController read GetController write SetController;
property ArticulosSeleccionados: IBizInventario read GetArticulosSeleccionados;
property MultiSelect : Boolean read GetMultiSelect write SetMultiSelect;
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;
procedure PonerTitulos(const ATitulo: string = ''); override;
end;
implementation
{$R *.DFM}
uses
cxControls, uGridUtils, uDataModuleInventario, uDataModuleUsuarios,
uEditorBase, uDBSelectionListUtils, cxGridDBTableView, cxGridCustomTableView,
uAlmacenesController, uFactuGES_App, uGestorInformesController,
//uGenerarAlbaranesProvUtils,
schInventarioClient_Intf;
{, uDBSelectionList, uDataModulePedidosProveedor,
uBizPedidosProveedor, uBizMontajes, uDataModuleMontajes;
}
{ TfEditorInventario }
{
***************************** TfEditorInventario *****************************
}
constructor TfEditorInventario.Create(AOwner: TComponent);
begin
inherited;
ViewGrid := frViewInventario1;
end;
function TfEditorInventario.DarIDAlmacenSeleccionado(Descripcion: String): Integer;
begin
if (ViewGrid._Grid.ActiveLevel.Tag = -1) then
Result := SeleccionarAlmacen(Descripcion)
else
Result := ViewGrid._Grid.ActiveLevel.Tag;
end;
destructor TfEditorInventario.Destroy;
begin
FInventario := NIL;
inherited;
end;
procedure TfEditorInventario.EliminarInterno;
var
IDAlmacenOrigen: Integer;
begin
IDAlmacenOrigen := darIDAlmacenSeleccionado('Elija el almac<61>n donde se realizar<61> la salida');
if IDAlmacenOrigen <> -1 then
begin
FController.SalidaArticulosLibre(FInventario, IDAlmacenOrigen);
RefrescarInterno;
end;
end;
procedure TfEditorInventario.FormShow(Sender: TObject);
begin
inherited;
if not Assigned(ViewGrid) then
raise Exception.Create('No hay ninguna vista asignada');
if not Assigned(Inventario) then
raise Exception.Create('No hay ning<6E>n inventario asignado');
Inventario.DataTable.Active := True;
actContraer.Execute;
ViewGrid.GotoFirst;
//Para que coja el ancho autom<6F>tico
actAnchoAuto.Execute;
end;
procedure TfEditorInventario.actModificarExecute(Sender: TObject);
begin
// inherited;
end;
procedure TfEditorInventario.actReservadosExecute(Sender: TObject);
begin
inherited;
FController.VerReservas(Inventario);
end;
procedure TfEditorInventario.actReservadosUpdate(Sender: TObject);
begin
inherited;
(Sender as TAction).Enabled := (Inventario.RESERVA > 0);
end;
function TfEditorInventario.GetAlmacenes: IBizAlmacen;
begin
Result := Nil;
if Assigned(ViewGrid) then
Result := (ViewGrid as IViewInventario).Almacenes;
end;
function TfEditorInventario.GetArticulosSeleccionados: IBizInventario;
begin
SeleccionarFilasDesdeGrid((ViewGrid as IViewInventario)._FocusedView, (Inventario as ISeleccionable).SelectedRecords);
// En Presupuestos.SelectedRecords tengo los ID de las filas seleccionadas del grid
Result := Controller.ExtraerSeleccionados(Inventario);
end;
function TfEditorInventario.GetController: IInventarioController;
begin
Result := FController;
end;
function TfEditorInventario.GetInventario: IBizInventario;
begin
Result := FInventario;
end;
function TfEditorInventario.GetMultiSelect: Boolean;
begin
Result := ViewGrid.MultiSelect;
end;
procedure TfEditorInventario.ImprimirInterno;
begin
inherited;
end;
procedure TfEditorInventario.NuevoInterno;
var
IDAlmacenDestino: Integer;
begin
IDAlmacenDestino := darIDAlmacenSeleccionado('Elija el almac<61>n donde se realizar<61> la entrada');
if IDAlmacenDestino <> -1 then
begin
FController.EntradaArticulosLibre(FInventario, IDAlmacenDestino);
RefrescarInterno;
end;
end;
procedure TfEditorInventario.PonerTitulos(const ATitulo: string);
var
FTitulo : String;
begin
FTitulo := 'Inventario de articulos en almacenes - ' + AppFactuGES.EmpresaActiva.NOMBRE;
inherited PonerTitulos(FTitulo);
end;
procedure TfEditorInventario.PrevisualizarInterno;
begin
inherited;
end;
function TfEditorInventario.SeleccionarAlmacen(Descripcion: String): Integer;
var
AAlmacenes : IBizAlmacen;
Respuesta : integer;
begin
Result := -1;
JsElegirAlmacenDialog.Instruction.Text := Descripcion;
with JsElegirAlmacenDialog.RadioButtons do
begin
Clear;
AAlmacenes := Almacenes;
AAlmacenes.First;
while not AAlmacenes.EOF do
begin
with Add do
begin
Caption := AAlmacenes.NOMBRE;
Value := 1000 + AAlmacenes.ID;
end;
//Asi sabemos que solo va a intentar chequear el primero si hemos a<>adido al menos un item
Items[0].Checked := True;
AAlmacenes.Next;
end;
end;
//Sacar la pantalla de selecci<63>n y devolver el almac<61>n seleccionado.
Respuesta := JsElegirAlmacenDialog.Execute;
if Respuesta <> IDCANCEL then
Result := JsElegirAlmacenDialog.RadioResult - 1000;
end;
procedure TfEditorInventario.SetAlmacenes(const Value: IBizAlmacen);
begin
if Assigned(ViewGrid) then
(ViewGrid as IViewInventario).Almacenes := Value;
end;
procedure TfEditorInventario.SetController(const Value: IInventarioController);
begin
FController := Value;
if Assigned(FController) then
begin
if Assigned(ViewGrid) then
Almacenes := FController.AlmacenesController.BuscarTodos;
end;
end;
procedure TfEditorInventario.SetInventario(const Value: IBizInventario);
begin
FInventario := Value;
dsDataTable.DataTable := FInventario.DataTable;
if Assigned(ViewGrid) then
(ViewGrid as IViewInventario).Inventario := FInventario;
end;
procedure TfEditorInventario.SetMultiSelect(AValue: Boolean);
begin
ViewGrid.MultiSelect := AValue;
end;
procedure TfEditorInventario.actRecibirPedidoExecute(Sender: TObject);
begin
inherited;
// RecibirPedidoProv;
RefrescarInterno;
end;
procedure TfEditorInventario.actTrasladarExecute(Sender: TObject);
var
IDAlmacenOrigen, IDAlmacenDestino: Integer;
begin
IDAlmacenOrigen := DarIDAlmacenSeleccionado('Elija el almac<61>n de origen (de donde salen los art<72>culos)');
if IDAlmacenOrigen <> -1 then
begin
IDAlmacenDestino := SeleccionarAlmacen('Elija el almac<61>n de destino (donde entran los art<72>culos)');
if IDAlmacenDestino <> -1 then
begin
FController.TrasladarArticulosLibre(FInventario, IDAlmacenOrigen, IDAlmacenDestino);
RefrescarInterno;
end;
end;
end;
procedure TfEditorInventario.actReservarExecute(Sender: TObject);
begin
Controller.Reservar(Inventario);
RefrescarInterno;
end;
procedure TfEditorInventario.actContraerExecute(Sender: TObject);
begin
if Assigned(ViewGrid) then
ViewGrid.ContraerTodo;
end;
procedure TfEditorInventario.actExpandirExecute(Sender: TObject);
begin
if Assigned(ViewGrid) then
ViewGrid.ExpandirTodo;
end;
procedure TfEditorInventario.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 inventario valorado compras 2 a<>os
AGestorInformesController.VerInformeInventarioValoradoCompras2Anos;
end;
end;
end;
finally
AGestorInformesController := NIL;
end;
end;
procedure TfEditorInventario.actLiberarExecute(Sender: TObject);
begin
Controller.Liberar(Inventario);
RefrescarInterno;
end;
procedure TfEditorInventario.actTrasladarUpdate(Sender: TObject);
begin
inherited;
{
if Assigned(dsDataTable.DataTable) then
(Sender as TAction).Enabled := (not dsDataTable.DataTable.IsEmpty)
else
(Sender as TAction).Enabled := False;
}
end;
procedure TfEditorInventario.actReservarUpdate(Sender: TObject);
begin
inherited;
{
if Assigned(dsDataTable.DataTable) then
(Sender as TAction).Enabled := (not dsDataTable.DataTable.IsEmpty)
else
(Sender as TAction).Enabled := False;
}
end;
procedure TfEditorInventario.actLiberarUpdate(Sender: TObject);
begin
inherited;
{
if Assigned(dsDataTable.DataTable) then
(Sender as TAction).Enabled := (not dsDataTable.DataTable.IsEmpty)
else
(Sender as TAction).Enabled := False;
}
end;
end.