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, dxGDIPlusClasses; type TEnumSeleccion = (tAlmacen, tObra, tAlmacenObra); 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; Image2: TImage; 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 actLiberarUpdate(Sender: TObject); procedure actExpandirExecute(Sender: TObject); procedure actContraerExecute(Sender: TObject); procedure FormShow(Sender: TObject); procedure actReservadosUpdate(Sender: TObject); procedure actReservadosExecute(Sender: TObject); private function Seleccionar(Descripcion: String; TipoSeleccion: TEnumSeleccion): Integer; function DarIDAlmacenSeleccionado(Descripcion: String): Integer; function DarIDObraSeleccionada(Descripcion: String): Integer; protected FTipoInventario: String; FInventario: IBizInventario; FController : IInventarioController; function GetTipoInventario: String; procedure SetTipoInventario(const Value: String); 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 TipoInventario: String read GetTipoInventario write SetTipoInventario; 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, uGridStatusUtils, uDataModuleInventario, uDataModuleUsuarios, uEditorBase, uDBSelectionListUtils, cxGridDBTableView, cxGridCustomTableView, uAlmacenesController, uFactuGES_App, uGenerarAlbaranesProvUtils, schInventarioClient_Intf, uBizObras; {, 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 := Seleccionar(Descripcion, tAlmacen) else Result := ViewGrid._Grid.ActiveLevel.Tag; end; function TfEditorInventario.DarIDObraSeleccionada(Descripcion: String): Integer; begin if (ViewGrid._Grid.ActiveLevel.Tag = -1) then Result := Seleccionar(Descripcion, TObra) else Result := ViewGrid._Grid.ActiveLevel.Tag; end; destructor TfEditorInventario.Destroy; begin FInventario := NIL; inherited; end; procedure TfEditorInventario.EliminarInterno; var IDAlmacenOrigen: Integer; begin if (TipoInventario = CTE_INV_ALMACEN) then IDAlmacenOrigen := darIDAlmacenSeleccionado('Elija el almacén donde se realizará la salida') else IDAlmacenOrigen := DarIDObraSeleccionada('Elija la obra donde se realizará 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ún inventario asignado'); Inventario.DataTable.Active := True; actContraer.Execute; ViewGrid.GotoFirst; end; procedure TfEditorInventario.actModificarExecute(Sender: TObject); begin // inherited; end; procedure TfEditorInventario.actReservadosExecute(Sender: TObject); begin inherited; FController.VerReservas(Inventario); RefrescarInterno; end; procedure TfEditorInventario.actReservadosUpdate(Sender: TObject); begin inherited; (Sender as TAction).Enabled := (Inventario.RESERVA > 0); 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; function TfEditorInventario.GetTipoInventario: String; begin Result := FTipoInventario; end; procedure TfEditorInventario.ImprimirInterno; begin inherited; end; procedure TfEditorInventario.NuevoInterno; var IDAlmacenDestino: Integer; begin if (TipoInventario = CTE_INV_ALMACEN) then IDAlmacenDestino := DarIDAlmacenSeleccionado('Elija el almacén donde se realizará la entrada') else IDAlmacenDestino := DarIDObraSeleccionada('Elija la obra donde se realizará la entrada'); if IDAlmacenDestino <> -1 then begin FController.EntradaArticulosLibre(FInventario, IDAlmacenDestino); RefrescarInterno; end; end; procedure TfEditorInventario.PonerTitulos(const ATitulo: string); var FTitulo : String; begin if (TipoInventario = CTE_INV_ALMACEN) then begin FTitulo := 'Inventario de articulos en almacenes - ' + AppFactuGES.EmpresaActiva.NOMBRE; Image2.Visible := False; Image1.Visible := True; end else begin FTitulo := 'Inventario de articulos en obras - ' + AppFactuGES.EmpresaActiva.NOMBRE; Image2.Visible := True; Image1.Visible := False; end; inherited PonerTitulos(FTitulo); end; procedure TfEditorInventario.PrevisualizarInterno; begin inherited; end; function TfEditorInventario.Seleccionar(Descripcion: String; TipoSeleccion: TEnumSeleccion): Integer; var AAlmacenes : IBizAlmacen; AObras : IBizObra; Respuesta : integer; begin Result := -1; AAlmacenes := Controller.AlmacenesController.BuscarTodos; AObras := Controller.ObrasController.BuscarTodos; AAlmacenes.DataTable.Active := True; AObras.DataTable.Active := True; JsElegirAlmacenDialog.Content.Clear; case TipoSeleccion of tAlmacen: JsElegirAlmacenDialog.Content.Add('¿Sobre que almacén desea realizar la operación?'); tObra: JsElegirAlmacenDialog.Content.Add('¿Sobre que obra desea realizar la operación?'); tAlmacenObra: JsElegirAlmacenDialog.Content.Add('¿Sobre que almacén / obra desea realizar la operación?'); end; JsElegirAlmacenDialog.Instruction.Text := Descripcion; JsElegirAlmacenDialog.RadioButtons.Clear; if TipoSeleccion in [tAlmacen, tAlmacenObra] then with JsElegirAlmacenDialog.RadioButtons do begin 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; if TipoSeleccion in [tObra, tAlmacenObra] then with JsElegirAlmacenDialog.RadioButtons do begin AObras.First; while not AObras.EOF do begin with Add do begin Caption := AObras.NOMBRE; Value := 1000 + AObras.ID; end; //Asi sabemos que solo va a intentar chequear el primero si hemos añadido al menos un item Items[0].Checked := True; AObras.Next; end; end; //Sacar la pantalla de selección y devolver el almacén seleccionado. Respuesta := JsElegirAlmacenDialog.Execute; if Respuesta <> IDCANCEL then Result := JsElegirAlmacenDialog.RadioResult - 1000; end; procedure TfEditorInventario.SetController(const Value: IInventarioController); begin FController := Value; 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.SetTipoInventario(const Value: String); begin FTipoInventario := Value; if not Assigned(FController) then raise Exception.Create('No hay ningún controlador asignado'); if (FTipoInventario = CTE_INV_ALMACEN) then begin if Assigned(ViewGrid) then (ViewGrid as IViewInventario).Almacenes := FController.AlmacenesController.BuscarTodos; end else if (FTipoInventario = CTE_INV_OBRA) then begin if Assigned(ViewGrid) then (ViewGrid as IViewInventario).Obras := FController.ObrasController.BuscarTodos; end; end; procedure TfEditorInventario.actRecibirPedidoExecute(Sender: TObject); begin inherited; RecibirPedidoProv; RefrescarInterno; end; procedure TfEditorInventario.actTrasladarExecute(Sender: TObject); var IDAlmacenOrigen, IDAlmacenDestino: Integer; begin if (TipoInventario = CTE_INV_ALMACEN) then IDAlmacenOrigen := DarIDAlmacenSeleccionado('Elija el almacén de origen (de donde salen los artículos)') else IDAlmacenOrigen := DarIDObraSeleccionada('Elija la obra de origen (de donde salen los artículos)'); if IDAlmacenOrigen <> -1 then begin IDAlmacenDestino := Seleccionar('Elija el almacén u obra de destino (donde entran los artículos)', tAlmacenObra); if IDAlmacenDestino <> -1 then begin FController.TrasladarArticulosLibre(FInventario, IDAlmacenOrigen, IDAlmacenDestino); RefrescarInterno; end; end; end; procedure TfEditorInventario.actReservarExecute(Sender: TObject); var IDAlmacenOrigen, IDAlmacenDestino: Integer; begin if (TipoInventario = CTE_INV_ALMACEN) then IDAlmacenOrigen := DarIDAlmacenSeleccionado('Elija el almacén donde desea reservar el material') else IDAlmacenOrigen := DarIDObraSeleccionada('Elija la obra donde desea reservar el material'); if IDAlmacenOrigen <> -1 then begin IDAlmacenDestino := Seleccionar('Elija el almacén/obra para el que desea reservar el material (donde irán los materiales)', tAlmacenObra); if IDAlmacenDestino <> -1 then begin FController.ReservarArticulosLibre(FInventario, IDAlmacenOrigen, IDAlmacenDestino); RefrescarInterno; end; end; 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.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.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.