git-svn-id: https://192.168.0.254/svn/Proyectos.LuisLeon_FactuGES/tags/1.0.9@15 c93665c3-c93d-084d-9b98-7d5f4a9c3376
335 lines
10 KiB
ObjectPascal
335 lines
10 KiB
ObjectPascal
unit uEditorAlbaranesCliente;
|
||
|
||
interface
|
||
|
||
uses
|
||
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
|
||
Dialogs, 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,
|
||
uBizAlbaranesCliente, uIEditorAlbaranesCliente, uAlbaranesClienteController,
|
||
uCustomView, uViewBase, uViewBarraSeleccion, uViewGridBase,
|
||
uViewAlbaranesCliente, JvExComCtrls, JvStatusBar, JSDialog;
|
||
|
||
type
|
||
TfEditorAlbaranesCliente = class(TfEditorGridBase, IEditorAlbaranesCliente)
|
||
JsNuevoAlbaranDialog: TJSDialog;
|
||
actGenerarFactura: TAction;
|
||
N4: TMenuItem;
|
||
Generarfactura1: TMenuItem;
|
||
TBXItem37: TTBXItem;
|
||
TBXSeparatorItem17: TTBXSeparatorItem;
|
||
actServirAlbaran: TAction;
|
||
Serviralbarn1: TMenuItem;
|
||
TBXItem38: TTBXItem;
|
||
JsListaFacturasGeneradas: TJSDialog;
|
||
procedure FormShow(Sender: TObject);
|
||
procedure actGenerarFacturaUpdate(Sender: TObject);
|
||
procedure actGenerarFacturaExecute(Sender: TObject);
|
||
procedure actServirAlbaranUpdate(Sender: TObject);
|
||
procedure actServirAlbaranExecute(Sender: TObject);
|
||
procedure actEliminarUpdate(Sender: TObject);
|
||
|
||
protected
|
||
FAlbaranes: IBizAlbaranCliente;
|
||
FController : IAlbaranesClienteController;
|
||
|
||
function GetAlbaranes: IBizAlbaranCliente;
|
||
procedure SetAlbaranes(const Value: IBizAlbaranCliente);
|
||
|
||
function GetController : IAlbaranesClienteController; virtual;
|
||
procedure SetController (const Value : IAlbaranesClienteController); 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 m<>todo
|
||
procedure AsignarVista; virtual;
|
||
|
||
public
|
||
procedure PonerTitulos(const ATitulo: string = ''); override;
|
||
property Albaranes: IBizAlbaranCliente read GetAlbaranes write SetAlbaranes;
|
||
property Controller : IAlbaranesClienteController read GetController write SetController;
|
||
constructor Create(AOwner: TComponent); override;
|
||
destructor Destroy; override;
|
||
end;
|
||
|
||
implementation
|
||
|
||
uses
|
||
uDataModuleAlbaranesCliente, uDataModuleUsuarios, uPedidosClienteController,
|
||
uBizPedidosCliente, uDialogUtils, schAlbaranesClienteClient_Intf,
|
||
uFacturasClienteController, uBizFacturasCliente, uInventarioController,
|
||
uEditorBase, uGenerarAlbaranesCliUtils, uGenerarFacturasCliAlbCliUtils;
|
||
|
||
{$R *.dfm}
|
||
|
||
{
|
||
*************************** TfEditorAlbaranesCliente ***************************
|
||
}
|
||
procedure TfEditorAlbaranesCliente.actEliminarUpdate(Sender: TObject);
|
||
begin
|
||
inherited;
|
||
(Sender as TAction).Enabled := HayDatos and
|
||
(FAlbaranes.SITUACION = SITUACION_ALBARAN_PENDIENTE);
|
||
end;
|
||
|
||
procedure TfEditorAlbaranesCliente.actGenerarFacturaExecute(Sender: TObject);
|
||
var
|
||
AFacturasController : IFacturasClienteController;
|
||
AListaFacturas : IBizFacturaCliente;
|
||
AAlbaranesElegidos : IBizAlbaranCliente;
|
||
i : integer;
|
||
begin
|
||
{
|
||
AFacturasController := TFacturasClienteController.Create;
|
||
try
|
||
AAlbaranesElegidos := FController.ElegirAlbaranes(FController.BuscarSinFacturar, 'Elija los albaranes que desea pasar a factura. Puede elegir albaranes de clientes diferentes.', True);
|
||
if Assigned(AAlbaranesElegidos) then
|
||
begin
|
||
AListaFacturas := AFacturasController.Nuevo;
|
||
if AFacturasController.Anadir(AListaFacturas, AAlbaranesElegidos) then
|
||
begin
|
||
if AListaFacturas.DataTable.RecordCount = 1 then
|
||
AFacturasController.Ver(AListaFacturas)
|
||
else begin
|
||
with JsListaFacturasGeneradas.Content do
|
||
begin
|
||
Clear;
|
||
AListaFacturas.DataTable.First;
|
||
for i := 0 to AListaFacturas.DataTable.RecordCount - 1 do
|
||
begin
|
||
if Length(AListaFacturas.REFERENCIA) > 0 then
|
||
Add(AListaFacturas.REFERENCIA + ': ' + AListaFacturas.NOMBRE);
|
||
AListaFacturas.DataTable.Next;
|
||
end;
|
||
end;
|
||
JsListaFacturasGeneradas.Execute;
|
||
end;
|
||
end;
|
||
}
|
||
GenerarFacturaCli(Albaranes.ID);
|
||
actRefrescar.Execute;
|
||
{
|
||
end;
|
||
finally
|
||
AFacturasController := NIL;
|
||
AListaFacturas := NIL;
|
||
AAlbaranesElegidos := NIL;
|
||
end;
|
||
}
|
||
end;
|
||
|
||
procedure TfEditorAlbaranesCliente.actGenerarFacturaUpdate(Sender: TObject);
|
||
begin
|
||
inherited;
|
||
(Sender as TAction).Enabled := HayDatos and (FAlbaranes.REF_FACTURA = '');
|
||
end;
|
||
|
||
procedure TfEditorAlbaranesCliente.actServirAlbaranExecute(Sender: TObject);
|
||
var
|
||
AInventarioController : IInventarioController;
|
||
bCambiarEstado : Boolean;
|
||
AFactura : IBizFacturaCliente;
|
||
AFacturasController : IFacturasClienteController;
|
||
AAlbaran : IBizAlbaranCliente;
|
||
begin
|
||
inherited;
|
||
bCambiarEstado := False;
|
||
|
||
// <20>Hay almac<61>n asociado al albar<61>n?
|
||
if FAlbaranes.ID_ALMACEN = 0 then
|
||
begin
|
||
if (ShowConfirmMessage('Env<6E>o de albar<61>n de cliente', 'Este albar<61>n no tiene un almac<61>n asociado por lo que no se realizar<61> ning<6E>n cambio en el stock de los almacenes.'
|
||
+ #10#13 + #10#13 + '<27>Desea realizar el env<6E>o de este albar<61>n de cliente?') = IDYES) then
|
||
bCambiarEstado := True // No hay almac<61>n. Cambiamos el estado y ya est<73>.
|
||
end
|
||
else begin
|
||
AInventarioController := TInventarioController.Create;
|
||
try
|
||
bCambiarEstado := AInventarioController.SalidaAlbaran(NIL, FAlbaranes.ID_ALMACEN, FAlbaranes.Detalles);
|
||
finally
|
||
AInventarioController := NIL;
|
||
end;
|
||
end;
|
||
|
||
if bCambiarEstado then
|
||
begin
|
||
try
|
||
FController.CambiarSituacion(FAlbaranes, SITUACION_ALBARAN_ENVIADO, Now);
|
||
if (ShowConfirmMessage('', 'Se ha realizado correctamente la salida del albar<61>n de cliente. <20>Desea generar la factura de cliente correspondiente?') = IDYES) then
|
||
begin
|
||
AAlbaran := FController.Buscar(FAlbaranes.ID);
|
||
AAlbaran.DataTable.Active := True;
|
||
|
||
AFacturasController := TFacturasClienteController.Create;
|
||
AFactura := AFacturasController.Nuevo;
|
||
try
|
||
if AFacturasController.Anadir(AFactura, AAlbaran) then
|
||
AFacturasController.Ver(AFactura)
|
||
finally
|
||
AFacturasController := NIL;
|
||
AAlbaran := NIL;
|
||
AFactura := NIL;
|
||
end;
|
||
end;
|
||
except
|
||
on E : Exception do
|
||
ShowErrorMessage('Error al cambiar la situaci<63>n del albar<61>n', E.Message, E);
|
||
end;
|
||
end;
|
||
actRefrescar.Execute;
|
||
end;
|
||
|
||
procedure TfEditorAlbaranesCliente.actServirAlbaranUpdate(Sender: TObject);
|
||
begin
|
||
inherited;
|
||
(Sender as TAction).Enabled := HayDatos and
|
||
(FAlbaranes.SITUACION = SITUACION_ALBARAN_PENDIENTE);
|
||
end;
|
||
|
||
procedure TfEditorAlbaranesCliente.AsignarVista;
|
||
begin
|
||
ViewGrid := CreateView(TfrViewAlbaranesCliente) as IViewAlbaranesCliente;
|
||
end;
|
||
|
||
constructor TfEditorAlbaranesCliente.Create(AOwner: TComponent);
|
||
begin
|
||
inherited;
|
||
AsignarVista;
|
||
end;
|
||
|
||
destructor TfEditorAlbaranesCliente.Destroy;
|
||
begin
|
||
FAlbaranes := NIL;
|
||
FController := NIL;
|
||
inherited;
|
||
end;
|
||
|
||
procedure TfEditorAlbaranesCliente.DuplicarInterno;
|
||
var
|
||
APedido : IBizAlbaranCliente;
|
||
begin
|
||
inherited;
|
||
APedido := FController.Duplicar(Albaranes);
|
||
try
|
||
FController.Ver(APedido);
|
||
finally
|
||
actRefrescar.Execute;
|
||
end;
|
||
end;
|
||
|
||
procedure TfEditorAlbaranesCliente.EliminarInterno;
|
||
begin
|
||
if (Application.MessageBox('<27>Desea borrar este albar<61>n de cliente?', 'Atenci<63>n', MB_YESNO) = IDYES) then
|
||
begin
|
||
FController.Eliminar(Albaranes);
|
||
inherited;
|
||
end;
|
||
end;
|
||
|
||
procedure TfEditorAlbaranesCliente.FormShow(Sender: TObject);
|
||
begin
|
||
inherited;
|
||
|
||
if not Assigned(ViewGrid) then
|
||
raise Exception.Create('No hay ninguna vista asignada');
|
||
|
||
if not Assigned(Albaranes) then
|
||
raise Exception.Create('No hay ning<6E>n albar<61>n asignado');
|
||
|
||
Albaranes.DataTable.Active := True;
|
||
ViewGrid.GotoFirst;
|
||
end;
|
||
|
||
function TfEditorAlbaranesCliente.GetController: IAlbaranesClienteController;
|
||
begin
|
||
Result := FController;
|
||
end;
|
||
|
||
function TfEditorAlbaranesCliente.GetAlbaranes: IBizAlbaranCliente;
|
||
begin
|
||
Result := FAlbaranes;
|
||
end;
|
||
|
||
procedure TfEditorAlbaranesCliente.ImprimirInterno;
|
||
begin
|
||
inherited;
|
||
FController.Preview(FAlbaranes);
|
||
end;
|
||
|
||
procedure TfEditorAlbaranesCliente.ModificarInterno;
|
||
begin
|
||
inherited;
|
||
FController.Ver(Albaranes);
|
||
end;
|
||
|
||
procedure TfEditorAlbaranesCliente.NuevoInterno;
|
||
var
|
||
Respuesta : Integer;
|
||
FPedidosClienteController : IPedidosClienteController;
|
||
APedido : IBizPedidoCliente;
|
||
begin
|
||
inherited;
|
||
|
||
Respuesta := JsNuevoAlbaranDialog.Execute;
|
||
|
||
if Respuesta <> IDCANCEL then
|
||
begin
|
||
case JsNuevoAlbaranDialog.CustomButtonResult of
|
||
200 : begin // Utilizar un pedido
|
||
FPedidosClienteController := TPedidosClienteController.Create;
|
||
try
|
||
APedido := FPedidosClienteController.ElegirPedidos(FPedidosClienteController.BuscarPendientes,
|
||
'Elija el pedido de cliente que desea utilizar para dar de alta el albar<61>n.', False);
|
||
if Assigned(APedido) then
|
||
GenerarAlbaranCli(APedido); // El proceso de generaci<63>n ya pregunta si el usuario quiere ver o no el albar<61>n generado.
|
||
finally
|
||
FPedidosClienteController := NIL;
|
||
end;
|
||
end;
|
||
100 : begin // Albaran nuevo vacio
|
||
if FController.Anadir(Albaranes) then
|
||
FController.Ver(Albaranes);
|
||
end;
|
||
end;
|
||
end;
|
||
end;
|
||
|
||
procedure TfEditorAlbaranesCliente.PonerTitulos(const ATitulo: string);
|
||
var
|
||
FTitulo : String;
|
||
begin
|
||
FTitulo := 'Lista de albaranes de cliente - ' + dmUsuarios.EmpresaActual.NOMBRE;
|
||
inherited PonerTitulos(FTitulo);
|
||
end;
|
||
|
||
procedure TfEditorAlbaranesCliente.PrevisualizarInterno;
|
||
begin
|
||
inherited;
|
||
FController.Preview(FAlbaranes);
|
||
end;
|
||
|
||
procedure TfEditorAlbaranesCliente.SetController(const Value: IAlbaranesClienteController);
|
||
begin
|
||
FController := Value;
|
||
end;
|
||
|
||
procedure TfEditorAlbaranesCliente.SetAlbaranes(const Value: IBizAlbaranCliente);
|
||
begin
|
||
FAlbaranes := Value;
|
||
dsDataTable.DataTable := FAlbaranes.DataTable;
|
||
if Assigned(ViewGrid) then
|
||
(ViewGrid as IViewAlbaranesCliente).Albaranes := Albaranes;
|
||
end;
|
||
|
||
end.
|