git-svn-id: https://192.168.0.254/svn/Proyectos.LuisLeon_FactuGES/trunk@2 c93665c3-c93d-084d-9b98-7d5f4a9c3376
312 lines
9.4 KiB
ObjectPascal
312 lines
9.4 KiB
ObjectPascal
unit uEditorFacturasCliente;
|
||
|
||
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,
|
||
uBizFacturasCliente, uIEditorFacturasCliente, uFacturasClienteController,
|
||
uCustomView, uViewBase, uViewBarraSeleccion, uViewGridBase,
|
||
uViewFacturasCliente, JvExComCtrls, JvStatusBar, JSDialog;
|
||
|
||
type
|
||
|
||
TfEditorFacturasCliente = class(TfEditorGridBase, IEditorFacturasCliente)
|
||
frViewFacturasCliente1: TfrViewFacturasCliente;
|
||
Cambiarlasituacin1: TMenuItem;
|
||
N4: TMenuItem;
|
||
JsNuevaFacturaDialog: TJSDialog;
|
||
JsListaFacturasGeneradas: TJSDialog;
|
||
JsPrevisualizarDialog: TJSDialog;
|
||
JsImprimirDialog: TJSDialog;
|
||
TBXSubmenuItem2: TTBXSubmenuItem;
|
||
actNuevaFactura: TAction;
|
||
TBXItem38: TTBXItem;
|
||
TBXItem39: TTBXItem;
|
||
actNuevoAbono: TAction;
|
||
JsNuevoAbonoDialog: TJSDialog;
|
||
procedure FormShow(Sender: TObject);
|
||
procedure actEliminarUpdate(Sender: TObject);
|
||
procedure actModificarUpdate(Sender: TObject);
|
||
procedure actNuevaFacturaExecute(Sender: TObject);
|
||
procedure actNuevoAbonoExecute(Sender: TObject);
|
||
private
|
||
FFacturas: IBizFacturaCliente;
|
||
FController : IFacturasClienteController;
|
||
protected
|
||
function GetFacturas: IBizFacturaCliente;
|
||
procedure SetFacturas(const Value: IBizFacturaCliente);
|
||
|
||
function GetController : IFacturasClienteController; virtual;
|
||
procedure SetController (const Value : IFacturasClienteController); virtual;
|
||
procedure NuevoInterno; override;
|
||
procedure EliminarInterno; override;
|
||
procedure ModificarInterno; override;
|
||
procedure DuplicarInterno; override;
|
||
procedure ImprimirInterno; override;
|
||
procedure PrevisualizarInterno; override;
|
||
public
|
||
procedure PonerTitulos(const ATitulo: string = ''); override;
|
||
property Facturas: IBizFacturaCliente read GetFacturas write SetFacturas;
|
||
property Controller : IFacturasClienteController read GetController write SetController;
|
||
constructor Create(AOwner: TComponent); override;
|
||
destructor Destroy; override;
|
||
end;
|
||
|
||
|
||
implementation
|
||
|
||
uses
|
||
uDataModuleFacturasCliente, uDataModuleUsuarios, uAlbaranesClienteController,
|
||
uPedidosClienteController, uBizAlbaranesCliente, uBizPedidosCliente,
|
||
uEditorBase, uGenerarFacturasCliAlbCliUtils;
|
||
|
||
{$R *.dfm}
|
||
|
||
{
|
||
*************************** TfEditorFacturasCliente ***************************
|
||
}
|
||
procedure TfEditorFacturasCliente.actEliminarUpdate(Sender: TObject);
|
||
begin
|
||
inherited;
|
||
if (Sender as TAction).Enabled then
|
||
(Sender as TAction).Enabled := HayDatos
|
||
and (FFacturas.SITUACION = 'PENDIENTE');
|
||
end;
|
||
|
||
procedure TfEditorFacturasCliente.actModificarUpdate(Sender: TObject);
|
||
begin
|
||
inherited;
|
||
if (Sender as TAction).Enabled then
|
||
(Sender as TAction).Enabled := HayDatos
|
||
and (FFacturas.SITUACION = 'PENDIENTE');
|
||
end;
|
||
|
||
procedure TfEditorFacturasCliente.actNuevaFacturaExecute(Sender: TObject);
|
||
begin
|
||
actNuevo.Execute;
|
||
end;
|
||
|
||
procedure TfEditorFacturasCliente.actNuevoAbonoExecute(Sender: TObject);
|
||
var
|
||
Respuesta : Integer;
|
||
Opcion : Integer;
|
||
begin
|
||
inherited;
|
||
//ABONOS
|
||
if (Facturas.TIPO = CTE_TIPO_FACTURA) then
|
||
begin
|
||
Respuesta := JsNuevoAbonoDialog.Execute;
|
||
//Nos salimos sin hace nada
|
||
if Respuesta = IDCANCEL then
|
||
Exit;
|
||
Opcion := JsNuevoAbonoDialog.CustomButtonResult;
|
||
end
|
||
else
|
||
Opcion := 100;
|
||
|
||
case Opcion of
|
||
200 : begin // Utilizar factura seleccionada
|
||
FController.Ver(FController.GenerarAbono(Facturas));
|
||
actRefrescar.Execute;
|
||
ViewGrid._FocusedView.DataController.GotoFirst;
|
||
end;
|
||
100 : begin // Abono nuevo vacio
|
||
if FController.AnadirAbono(Facturas) then
|
||
FController.Ver(Facturas);
|
||
end;
|
||
end;
|
||
end;
|
||
|
||
constructor TfEditorFacturasCliente.Create(AOwner: TComponent);
|
||
begin
|
||
inherited;
|
||
ViewGrid := frViewFacturasCliente1; // CreateView(TfrViewFacturasCliente) as IViewFacturasCliente;
|
||
end;
|
||
|
||
destructor TfEditorFacturasCliente.Destroy;
|
||
begin
|
||
FFacturas := NIL;
|
||
inherited;
|
||
end;
|
||
|
||
procedure TfEditorFacturasCliente.DuplicarInterno;
|
||
var
|
||
AFactura : IBizFacturaCliente;
|
||
begin
|
||
inherited;
|
||
AFactura := FController.Duplicar(FFacturas);
|
||
try
|
||
FController.Ver(AFactura);
|
||
finally
|
||
actRefrescar.Execute;
|
||
end;
|
||
end;
|
||
|
||
procedure TfEditorFacturasCliente.EliminarInterno;
|
||
var
|
||
ACadena : String;
|
||
begin
|
||
if Facturas.TIPO = CTE_TIPO_FACTURA then
|
||
ACadena := '<27>Desea borrar esta factura de cliente?'
|
||
else
|
||
ACadena := '<27>Desea borrar este abono a cliente?';
|
||
|
||
if (Application.MessageBox(PChar(ACadena), 'Atenci<63>n', MB_YESNO) = IDYES) then
|
||
begin
|
||
FController.Eliminar(Facturas);
|
||
inherited;
|
||
end;
|
||
end;
|
||
|
||
procedure TfEditorFacturasCliente.FormShow(Sender: TObject);
|
||
begin
|
||
inherited;
|
||
|
||
if not Assigned(ViewGrid) then
|
||
raise Exception.Create('No hay ninguna vista asignada');
|
||
|
||
if not Assigned(Facturas) then
|
||
raise Exception.Create('No hay ninguna factura asignada');
|
||
|
||
Facturas.DataTable.Active := True;
|
||
ViewGrid.GotoFirst;
|
||
end;
|
||
|
||
function TfEditorFacturasCliente.GetController: IFacturasClienteController;
|
||
begin
|
||
Result := FController;
|
||
end;
|
||
|
||
function TfEditorFacturasCliente.GetFacturas: IBizFacturaCliente;
|
||
begin
|
||
Result := FFacturas;
|
||
end;
|
||
|
||
procedure TfEditorFacturasCliente.ImprimirInterno;
|
||
var
|
||
Respuesta : Integer;
|
||
begin
|
||
//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
|
||
FController.Print(Facturas);
|
||
end;
|
||
end;
|
||
end;
|
||
end;
|
||
end;
|
||
|
||
procedure TfEditorFacturasCliente.ModificarInterno;
|
||
begin
|
||
inherited;
|
||
FController.Ver(Facturas);
|
||
end;
|
||
|
||
procedure TfEditorFacturasCliente.NuevoInterno;
|
||
var
|
||
Respuesta : Integer;
|
||
//FPedidosClienteController : IPedidosClienteController;
|
||
//APedido : IBizPedidoCliente;
|
||
//FAlbaranesClienteController : IAlbaranesClienteController;
|
||
//AAlbaranes : IBizAlbaranCliente;
|
||
//AFacturasNuevas : IBizFacturaCliente;
|
||
//i : integer;
|
||
begin
|
||
inherited;
|
||
|
||
Respuesta := JsNuevaFacturaDialog.Execute;
|
||
|
||
if Respuesta <> IDCANCEL then
|
||
begin
|
||
case JsNuevaFacturaDialog.CustomButtonResult of
|
||
300 : begin // Utilizar un pedido
|
||
ShowMessage('A COMPLETAR');
|
||
{FPedidosClienteController := TPedidosClienteController.Create;
|
||
try
|
||
APedido := FPedidosClienteController.ElegirPedidos(FPedidosClienteController.BuscarPendientes,
|
||
'Elija el pedido de cliente que desea utilizar para dar de alta la factura.'
|
||
+ #10#13 + 'Tenga en cuenta que s<>lo se podr<64>n utilizar pedidos que no tengan ning<6E>n albar<61>n ya asociado.', False);
|
||
if Assigned(APedido) then
|
||
begin
|
||
if FController.Anadir(Facturas, APedido) then
|
||
FController.Ver(Facturas);
|
||
end;
|
||
finally
|
||
FPedidosClienteController := NIL;
|
||
end;}
|
||
end;
|
||
200 : begin // Utilizar albaranes
|
||
GenerarFacturaCli;
|
||
actRefrescar.Execute;
|
||
end;
|
||
100 : begin // Albaran nuevo vacio
|
||
if FController.Anadir(Facturas) then
|
||
FController.Ver(Facturas);
|
||
end;
|
||
end;
|
||
end;
|
||
end;
|
||
|
||
procedure TfEditorFacturasCliente.PonerTitulos(const ATitulo: string);
|
||
var
|
||
FTitulo : String;
|
||
begin
|
||
FTitulo := 'Lista de facturas de cliente - ' + dmUsuarios.EmpresaActual.NOMBRE;
|
||
inherited PonerTitulos(FTitulo);
|
||
end;
|
||
|
||
procedure TfEditorFacturasCliente.PrevisualizarInterno;
|
||
var
|
||
Respuesta : Integer;
|
||
begin
|
||
//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
|
||
FController.Preview(Facturas);
|
||
end;
|
||
end;
|
||
end;
|
||
end;
|
||
end;
|
||
|
||
procedure TfEditorFacturasCliente.SetController(const Value: IFacturasClienteController);
|
||
begin
|
||
FController := Value;
|
||
end;
|
||
|
||
procedure TfEditorFacturasCliente.SetFacturas(const Value: IBizFacturaCliente);
|
||
begin
|
||
FFacturas := Value;
|
||
dsDataTable.DataTable := FFacturas.DataTable;
|
||
if Assigned(ViewGrid) then
|
||
(ViewGrid as IViewFacturasCliente).Facturas := Facturas;
|
||
end;
|
||
|
||
end.
|