392 lines
12 KiB
ObjectPascal
392 lines
12 KiB
ObjectPascal
|
|
unit uEditorPresupuestosCliente;
|
|||
|
|
|
|||
|
|
interface
|
|||
|
|
|
|||
|
|
uses
|
|||
|
|
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
|
|||
|
|
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,
|
|||
|
|
uBizPresupuestosCliente, uIEditorPresupuestosCliente, uPresupuestosClienteController,
|
|||
|
|
uCustomView, uViewBase, uViewBarraSeleccion, uViewGridBase,
|
|||
|
|
uViewPresupuestosCliente, JvExComCtrls, JvStatusBar, JSDialog, StdCtrls,
|
|||
|
|
uDAInterfaces;
|
|||
|
|
|
|||
|
|
type
|
|||
|
|
TfEditorPresupuestosCliente = class(TfEditorGridBase, IEditorPresupuestosCliente)
|
|||
|
|
actGenerarAlbaranCli: TAction;
|
|||
|
|
actGenerarFactura: TAction;
|
|||
|
|
actGenerarPedidoProv: TAction;
|
|||
|
|
TBXSubmenuItem2: TTBXSubmenuItem;
|
|||
|
|
TBXSeparatorItem17: TTBXSeparatorItem;
|
|||
|
|
TBXItem38: TTBXItem;
|
|||
|
|
TBXItem39: TTBXItem;
|
|||
|
|
N4: TMenuItem;
|
|||
|
|
actGenerar: TAction;
|
|||
|
|
Generar2: TMenuItem;
|
|||
|
|
JsGenerarDialog: TJSDialog;
|
|||
|
|
JsPrevisualizarDialog: TJSDialog;
|
|||
|
|
JsImprimirDialog: TJSDialog;
|
|||
|
|
TBXItem40: TTBXItem;
|
|||
|
|
JsListaPedidosNoEliminados: TJSDialog;
|
|||
|
|
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);
|
|||
|
|
|
|||
|
|
protected
|
|||
|
|
FPedidos: IBizPresupuestoCliente;
|
|||
|
|
FController : IPresupuestosClienteController;
|
|||
|
|
|
|||
|
|
function GetPedidos: IBizPresupuestoCliente;
|
|||
|
|
procedure SetPedidos(const Value: IBizPresupuestoCliente);
|
|||
|
|
|
|||
|
|
function GetController : IPresupuestosClienteController; virtual;
|
|||
|
|
procedure SetController (const Value : IPresupuestosClienteController); virtual;
|
|||
|
|
|
|||
|
|
procedure NuevoInterno; override;
|
|||
|
|
procedure ModificarInterno; override;
|
|||
|
|
procedure EliminarInterno; override;
|
|||
|
|
procedure DuplicarInterno; override;
|
|||
|
|
procedure ImprimirInterno; override;
|
|||
|
|
procedure PrevisualizarInterno; 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: IBizPresupuestoCliente read GetPedidos write SetPedidos;
|
|||
|
|
property Controller : IPresupuestosClienteController read GetController write SetController;
|
|||
|
|
constructor Create(AOwner: TComponent); override;
|
|||
|
|
destructor Destroy; override;
|
|||
|
|
end;
|
|||
|
|
|
|||
|
|
implementation
|
|||
|
|
|
|||
|
|
uses
|
|||
|
|
uDataModulePresupuestosCliente, uDataModuleUsuarios,
|
|||
|
|
// uBizAlbaranesCliente, uAlbaranesClienteController,
|
|||
|
|
uEditorBase, uEditorDBBase, uDialogUtils,
|
|||
|
|
// uFacturasClienteController, uBizFacturasCliente,
|
|||
|
|
uGridUtils, uDBSelectionListUtils;
|
|||
|
|
// uGenerarPedidosProvUtils, uGenerarAlbaranesCliUtils;
|
|||
|
|
|
|||
|
|
|
|||
|
|
{$R *.dfm}
|
|||
|
|
|
|||
|
|
{
|
|||
|
|
*************************** TfEditorPresupuestosCliente ***************************
|
|||
|
|
}
|
|||
|
|
procedure TfEditorPresupuestosCliente.actEliminarUpdate(Sender: TObject);
|
|||
|
|
begin
|
|||
|
|
inherited;
|
|||
|
|
if (Sender as TAction).Enabled then
|
|||
|
|
(Sender as TAction).Enabled := (FPedidos.SITUACION = SITUACION_PEDIDO_PENDIENTE);
|
|||
|
|
end;
|
|||
|
|
|
|||
|
|
procedure TfEditorPresupuestosCliente.actGenerarAlbaranCliExecute(Sender: TObject);
|
|||
|
|
var
|
|||
|
|
IDAlbaranAux : Integer;
|
|||
|
|
begin
|
|||
|
|
inherited;
|
|||
|
|
// GenerarAlbaranCli(FPedidos.ID, IDAlbaranAux);
|
|||
|
|
end;
|
|||
|
|
|
|||
|
|
procedure TfEditorPresupuestosCliente.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 TfEditorPresupuestosCliente.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 TfEditorPresupuestosCliente.actGenerarFacturaUpdate(Sender: TObject);
|
|||
|
|
begin
|
|||
|
|
inherited;
|
|||
|
|
(Sender as TAction).Enabled := HayDatos
|
|||
|
|
and ViewGrid.esSeleccionCeldaDatos
|
|||
|
|
and (FPedidos.SITUACION = SITUACION_PEDIDO_PENDIENTE);
|
|||
|
|
end;
|
|||
|
|
|
|||
|
|
procedure TfEditorPresupuestosCliente.actGenerarPedidoProvExecute(Sender: TObject);
|
|||
|
|
begin
|
|||
|
|
inherited;
|
|||
|
|
// GenerarPedidosProv(FPedidos);
|
|||
|
|
end;
|
|||
|
|
|
|||
|
|
procedure TfEditorPresupuestosCliente.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 TfEditorPresupuestosCliente.AsignarVista;
|
|||
|
|
begin
|
|||
|
|
ViewGrid := CreateView(TfrViewPresupuestosCliente) as IViewPresupuestosCliente;
|
|||
|
|
end;
|
|||
|
|
|
|||
|
|
constructor TfEditorPresupuestosCliente.Create(AOwner: TComponent);
|
|||
|
|
begin
|
|||
|
|
inherited;
|
|||
|
|
AsignarVista;
|
|||
|
|
end;
|
|||
|
|
|
|||
|
|
destructor TfEditorPresupuestosCliente.Destroy;
|
|||
|
|
begin
|
|||
|
|
FPedidos := NIL;
|
|||
|
|
FController := NIL;
|
|||
|
|
inherited;
|
|||
|
|
end;
|
|||
|
|
|
|||
|
|
procedure TfEditorPresupuestosCliente.DuplicarInterno;
|
|||
|
|
var
|
|||
|
|
APedido : IBizPresupuestoCliente;
|
|||
|
|
begin
|
|||
|
|
inherited;
|
|||
|
|
APedido := FController.Duplicar(Pedidos);
|
|||
|
|
try
|
|||
|
|
FController.Ver(APedido);
|
|||
|
|
finally
|
|||
|
|
actRefrescar.Execute;
|
|||
|
|
end;
|
|||
|
|
end;
|
|||
|
|
|
|||
|
|
procedure TfEditorPresupuestosCliente.EliminarInterno;
|
|||
|
|
var
|
|||
|
|
APedidos: IBizPresupuestoCliente;
|
|||
|
|
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 IPresupuestosClienteController).ExtraerSeleccionados(Pedidos) as IBizPresupuestoCliente;
|
|||
|
|
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 TfEditorPresupuestosCliente.FormShow(Sender: TObject);
|
|||
|
|
begin
|
|||
|
|
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 TfEditorPresupuestosCliente.GetController: IPresupuestosClienteController;
|
|||
|
|
begin
|
|||
|
|
Result := FController;
|
|||
|
|
end;
|
|||
|
|
|
|||
|
|
function TfEditorPresupuestosCliente.GetPedidos: IBizPresupuestoCliente;
|
|||
|
|
begin
|
|||
|
|
Result := FPedidos;
|
|||
|
|
end;
|
|||
|
|
|
|||
|
|
procedure TfEditorPresupuestosCliente.ImprimirInterno;
|
|||
|
|
var
|
|||
|
|
Respuesta : Integer;
|
|||
|
|
APedidos: IBizPresupuestoCliente;
|
|||
|
|
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 IPresupuestosClienteController).ExtraerSeleccionados(Pedidos) as IBizPresupuestoCliente;
|
|||
|
|
end
|
|||
|
|
else
|
|||
|
|
APedidos := Pedidos;
|
|||
|
|
|
|||
|
|
if Assigned(APedidos) then
|
|||
|
|
FController.Print(APedidos, AllItems);
|
|||
|
|
end;
|
|||
|
|
end;
|
|||
|
|
end;
|
|||
|
|
end;
|
|||
|
|
end;
|
|||
|
|
|
|||
|
|
procedure TfEditorPresupuestosCliente.ModificarInterno;
|
|||
|
|
begin
|
|||
|
|
inherited;
|
|||
|
|
FController.Ver(Pedidos);
|
|||
|
|
end;
|
|||
|
|
|
|||
|
|
procedure TfEditorPresupuestosCliente.NuevoInterno;
|
|||
|
|
begin
|
|||
|
|
inherited;
|
|||
|
|
if FController.Anadir(Pedidos) then
|
|||
|
|
FController.Ver(Pedidos);
|
|||
|
|
end;
|
|||
|
|
|
|||
|
|
procedure TfEditorPresupuestosCliente.PonerTitulos(const ATitulo: string);
|
|||
|
|
var
|
|||
|
|
FTitulo : String;
|
|||
|
|
begin
|
|||
|
|
FTitulo := 'Lista de pedidos de cliente - '; //+ dmUsuarios.EmpresaActual.NOMBRE;
|
|||
|
|
inherited PonerTitulos(FTitulo);
|
|||
|
|
end;
|
|||
|
|
|
|||
|
|
procedure TfEditorPresupuestosCliente.PrevisualizarInterno;
|
|||
|
|
var
|
|||
|
|
Respuesta : Integer;
|
|||
|
|
APedidos: IBizPresupuestoCliente;
|
|||
|
|
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 IPresupuestosClienteController).ExtraerSeleccionados(Pedidos) as IBizPresupuestoCliente;
|
|||
|
|
end
|
|||
|
|
else
|
|||
|
|
APedidos := Pedidos;
|
|||
|
|
|
|||
|
|
if Assigned(APedidos) then
|
|||
|
|
FController.Preview(APedidos, AllItems);
|
|||
|
|
end;
|
|||
|
|
end;
|
|||
|
|
end;
|
|||
|
|
end;
|
|||
|
|
end;
|
|||
|
|
|
|||
|
|
procedure TfEditorPresupuestosCliente.SetController(const Value: IPresupuestosClienteController);
|
|||
|
|
begin
|
|||
|
|
FController := Value;
|
|||
|
|
end;
|
|||
|
|
|
|||
|
|
procedure TfEditorPresupuestosCliente.SetPedidos(const Value: IBizPresupuestoCliente);
|
|||
|
|
begin
|
|||
|
|
FPedidos := Value;
|
|||
|
|
dsDataTable.DataTable := FPedidos.DataTable;
|
|||
|
|
if Assigned(ViewGrid) then
|
|||
|
|
(ViewGrid as IViewPresupuestosCliente).Pedidos := Pedidos;
|
|||
|
|
end;
|
|||
|
|
|
|||
|
|
end.
|