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, uEditorElegirAlmacenObraOperacion; 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; frViewInventario1: TfrViewInventario; 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); procedure actNuevoUpdate(Sender: TObject); procedure actEliminarUpdate(Sender: TObject); procedure actRecibirPedidoUpdate(Sender: TObject); procedure actReservarUpdate(Sender: TObject); private function Seleccionar(Descripcion: String; TipoSeleccion: TEnumSeleccion): Variant; 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 Variants, 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; var IDAlmacen: Variant; begin IDAlmacen := (ViewGrid as IViewInventario).DarIDAlmacenObraSeleccionada; if not VarIsNull(IDAlmacen) then Result := IDAlmacen else Result := Seleccionar(Descripcion, tAlmacen) end; function TfEditorInventario.DarIDObraSeleccionada(Descripcion: String): Integer; var IDObra: Variant; begin IDObra := (ViewGrid as IViewInventario).DarIDAlmacenObraSeleccionada; if not VarIsNull(IDObra) then Result := IDObra else Result := Seleccionar(Descripcion, TObra) end; destructor TfEditorInventario.Destroy; begin FInventario := NIL; inherited; end; procedure TfEditorInventario.EliminarInterno; var IDAlmacenOrigen: Variant; 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 not VarIsNull(IDAlmacenOrigen) 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.actNuevoUpdate(Sender: TObject); begin inherited; if (Sender as TAction).Enabled then (Sender as TAction).Enabled := not (ViewGrid as IViewInventario).ListaAlmacenesObrasVacia; end; procedure TfEditorInventario.actReservadosExecute(Sender: TObject); begin inherited; FController.VerReservas(Inventario, TipoInventario, (ViewGrid as IViewInventario).DarIDAlmacenObraSeleccionada); 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: Variant; 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 not VarIsNull(IDAlmacenDestino) 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): Variant; var ALista : TStringList; AListaAux : TStringList; Respuesta : Variant; i: Integer; begin Result := Null; with TfEditorElegirAlmacenObraOperacion.Create(NIL) do try case TipoSeleccion of tAlmacen: begin Caption := Descripcion; eDescripcion.Caption := 'Elija sobre qué almacén desea realizar la operación.'; eEtiqueta.Caption := 'Almacén:'; ALista := Controller.AlmacenesController.DarListaAlmacenes; end; tObra: begin Caption := Descripcion; eDescripcion.Caption := 'Elija sobre qué obra desea realizar la operación.'; eEtiqueta.Caption := 'Obra:'; ALista := Controller.ObrasController.DarListaObras; end; tAlmacenObra: begin Caption := Descripcion; eDescripcion.Caption := 'Elija sobre qué almacén u obra desea realizar la operación.'; eEtiqueta.Caption := 'Almacén/Obra:'; ALista := Controller.AlmacenesController.DarListaAlmacenes; AListaAux := Controller.ObrasController.DarListaObras; for i := 0 to AListaAux.Count - 1 do ALista.Add(Format('%s=%s', [AListaAux.Names[i], AListaAux.Values[AListaAux.Names[i]]])); end; end; with cxListaAlmacenesObras.Properties.Items do begin BeginUpdate; try Clear; for i := 0 to ALista.Count - 1 do Add(ALista.Names[i]); finally EndUpdate; end; end; if (ShowModal = mrOk) then Result := ALista.Values[cxListaAlmacenesObras.EditValue]; finally Free; end; 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.DarListaAlmacenes; end else if (FTipoInventario = CTE_INV_OBRA) then begin if Assigned(ViewGrid) then (ViewGrid as IViewInventario).Obras := FController.ObrasController.DarListaObras; end; end; procedure TfEditorInventario.actRecibirPedidoExecute(Sender: TObject); begin inherited; RecibirPedidoProv; RefrescarInterno; end; procedure TfEditorInventario.actRecibirPedidoUpdate(Sender: TObject); begin inherited; if (Sender as TAction).Enabled then (Sender as TAction).Enabled := not (ViewGrid as IViewInventario).ListaAlmacenesObrasVacia; end; procedure TfEditorInventario.actTrasladarExecute(Sender: TObject); var IDAlmacenOrigen, IDAlmacenDestino: Variant; 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 not VarIsnull(IDAlmacenOrigen) then begin IDAlmacenDestino := Seleccionar('Elija el almacén u obra de destino (donde entran los artículos)', tAlmacenObra); if not VarIsNull(IDAlmacenDestino) then begin FController.TrasladarArticulosLibre(FInventario, IDAlmacenOrigen, IDAlmacenDestino); RefrescarInterno; end; end; end; procedure TfEditorInventario.actReservarExecute(Sender: TObject); var IDAlmacenOrigen, IDAlmacenDestino: Variant; 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 not VarIsNull(IDAlmacenOrigen) then begin IDAlmacenDestino := Seleccionar('Elija el almacén/obra para el que desea reservar el material (donde irán los materiales)', tAlmacenObra); if not VarIsNull(IDAlmacenDestino) then begin FController.ReservarArticulosLibre(FInventario, IDAlmacenOrigen, IDAlmacenDestino); RefrescarInterno; end; end; end; procedure TfEditorInventario.actReservarUpdate(Sender: TObject); begin inherited; if (Sender as TAction).Enabled then (Sender as TAction).Enabled := Assigned(dsDataTable.DataTable); if (Sender as TAction).Enabled then (Sender as TAction).Enabled := not (ViewGrid as IViewInventario).ListaAlmacenesObrasVacia; end; procedure TfEditorInventario.actContraerExecute(Sender: TObject); begin if Assigned(ViewGrid) then ViewGrid.ContraerTodo; end; procedure TfEditorInventario.actEliminarUpdate(Sender: TObject); begin inherited; if (Sender as TAction).Enabled then (Sender as TAction).Enabled := not (ViewGrid as IViewInventario).ListaAlmacenesObrasVacia; 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 (Sender as TAction).Enabled then (Sender as TAction).Enabled := Assigned(dsDataTable.DataTable); if (Sender as TAction).Enabled then (Sender as TAction).Enabled := not (ViewGrid as IViewInventario).ListaAlmacenesObrasVacia; 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.