2009-12-16 17:16:54 +00:00
unit uEditorPresupuestosCliente;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Menus, DB, uDADataTable, JvAppStorage,
JvAppRegistryStorage, JvComponent, JvFormPlacement, ImgList,
2010-01-22 09:52:58 +00:00
PngImageList, StdActns, ActnList, ComCtrls, TB2ExtItems,
SpTBXItem, TB2Item, TB2Dock, TB2Toolbar, ExtCtrls, JvExControls,
2009-12-16 17:16:54 +00:00
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;
2010-01-22 09:52:58 +00:00
TBXSubmenuItem2: TSpTBXSubmenuItem;
TBXSeparatorItem17: TSpTBXSeparatorItem;
TBXItem38: TSpTBXItem;
TBXItem39: TSpTBXItem;
2009-12-16 17:16:54 +00:00
N4: TMenuItem;
Generar2: TMenuItem;
JsGenerarDialog: TJSDialog;
JsPrevisualizarDialog: TJSDialog;
JsImprimirDialog: TJSDialog;
2010-01-22 09:52:58 +00:00
TBXItem40: TSpTBXItem;
2009-12-16 17:16:54 +00:00
JsListaPresupuestosNoEliminados: TJSDialog;
actGenerarCertificado: TAction;
2010-01-22 09:52:58 +00:00
TBXItem41: TSpTBXItem;
TBXItem42: TSpTBXItem;
2009-12-16 17:16:54 +00:00
Generarcertificado1: TMenuItem;
actAceptar: TAction;
actAnular: TAction;
2010-01-22 09:52:58 +00:00
TBXItem43: TSpTBXItem;
TBXItem44: TSpTBXItem;
TBXSeparatorItem18: TSpTBXSeparatorItem;
2009-12-16 17:16:54 +00:00
actEnviarEMail: TAction;
2010-01-22 09:52:58 +00:00
TBXItem45: TSpTBXItem;
2009-12-16 17:16:54 +00:00
Enviarporemail1: TMenuItem;
actInformes: TAction;
2010-01-22 09:52:58 +00:00
TBXItem46: TSpTBXItem;
2009-12-16 17:16:54 +00:00
JSInformesDialog: TJSDialog;
2010-01-22 09:52:58 +00:00
TBXItem47: TSpTBXItem;
2009-12-16 17:16:54 +00:00
procedure FormShow( Sender: TObject) ;
procedure actGenerarAlbaranCliExecute( Sender: TObject) ;
procedure actEliminarUpdate( Sender: TObject) ;
procedure actGenerarFacturaUpdate( Sender: TObject) ;
procedure actGenerarFacturaExecute( Sender: TObject) ;
procedure actGenerarPresupuestoProvExecute( Sender: TObject) ;
procedure actGenerarExecute( Sender: TObject) ;
procedure actGenerarCertificadoUpdate( Sender: TObject) ;
procedure actGenerarCertificadoExecute( Sender: TObject) ;
procedure actAceptarExecute( Sender: TObject) ;
procedure actAceptarUpdate( Sender: TObject) ;
procedure actAnularExecute( Sender: TObject) ;
procedure actAnularUpdate( Sender: TObject) ;
procedure actEnviarEMailExecute( Sender: TObject) ;
procedure actEnviarEMailUpdate( Sender: TObject) ;
procedure actInformesExecute( Sender: TObject) ;
2010-01-22 09:52:58 +00:00
procedure OnListaAnosChange( Sender: TObject) ;
2009-12-16 17:16:54 +00:00
protected
FPresupuestos: IBizPresupuestoCliente;
FController : IPresupuestosClienteController;
function GetPresupuestos: IBizPresupuestoCliente;
procedure SetPresupuestos( 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 ;
procedure RefrescarInterno; 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 Presupuestos: IBizPresupuestoCliente read GetPresupuestos write SetPresupuestos;
property Controller : IPresupuestosClienteController read GetController write SetController;
constructor Create( AOwner: TComponent) ; override ;
destructor Destroy; override ;
end ;
implementation
uses
uDataModulePresupuestosCliente, uDataModuleUsuarios, uFactuGES_App,
uEditorBase, uEditorDBBase, uDialogUtils, Dialogs,
uDBSelectionListUtils, uGridStatusUtils,
uGenerarFacturasCliPreCliUtils, uEditorFechaDecision,
// uBizAlbaranesCliente, uAlbaranesClienteController,
// uFacturasClienteController, uBizFacturasCliente,
uGenerarAlbaranesCliUtils, uGestorInformesController;
{$R *.dfm}
{
* * * * * * * * * * * * * * * * * * * * * * * * * * * TfEditorPresupuestosCliente * * * * * * * * * * * * * * * * * * * * * * * * * * *
}
procedure TfEditorPresupuestosCliente. actAceptarExecute( Sender: TObject) ;
var
APresupuestos: IBizPresupuestoCliente;
AllItems: Boolean ;
AFecha: Variant ;
begin
APresupuestos : = Nil ;
AllItems : = False ;
//Pedimos fecha de decision y realizamos todo el proceso de asignacion, en el caso de no darla no se hace nada
AFecha : = Null;
with TfEditorFechaDecision. Create( nil ) do
try
if ShowModal = mrOk then
AFecha : = edtFechaDecision. Date;
finally
Free;
end ;
if not VarIsNull( AFecha) then
begin
if MultiSelect and Assigned( ViewGrid) then
AllItems : = ( ViewGrid. NumSeleccionados > 1 ) ;
if AllItems then
begin
SeleccionarFilasDesdeGrid( ViewGrid. _FocusedView, ( Presupuestos as ISeleccionable) . SelectedRecords) ;
APresupuestos : = ( Controller as IPresupuestosClienteController) . ExtraerSeleccionados( Presupuestos) as IBizPresupuestoCliente;
end
else begin
APresupuestos : = Presupuestos;
end ;
ViewGrid. _Grid. BeginUpdate;
if Assigned( APresupuestos) then
begin
FController. CambiarSituacion( APresupuestos, SITUACION_PRESUPUESTO_ACEPTADO, AFecha, AllItems) ;
actRefrescar. Execute;
end ;
ViewGrid. _Grid. EndUpdate;
end ;
end ;
procedure TfEditorPresupuestosCliente. actAceptarUpdate( Sender: TObject) ;
begin
inherited ;
( Sender as TAction) . Enabled : = HayDatos
and ViewGrid. esSeleccionCeldaDatos
and ( FPresupuestos. SITUACION < > SITUACION_PRESUPUESTO_ACEPTADO) ;
end ;
procedure TfEditorPresupuestosCliente. actAnularExecute( Sender: TObject) ;
var
APresupuestos: IBizPresupuestoCliente;
AllItems: Boolean ;
AFecha: Variant ;
begin
APresupuestos : = Nil ;
AllItems : = False ;
//Pedimos fecha de decision y realizamos todo el proceso de asignacion, en el caso de no darla no se hace nada
AFecha : = Null;
with TfEditorFechaDecision. Create( nil ) do
try
if ShowModal = mrOk then
AFecha : = edtFechaDecision. Date;
finally
Free;
end ;
if not VarIsNull( AFecha) then
begin
if MultiSelect and Assigned( ViewGrid) then
AllItems : = ( ViewGrid. NumSeleccionados > 1 ) ;
if AllItems then
begin
SeleccionarFilasDesdeGrid( ViewGrid. _FocusedView, ( Presupuestos as ISeleccionable) . SelectedRecords) ;
APresupuestos : = ( Controller as IPresupuestosClienteController) . ExtraerSeleccionados( Presupuestos) as IBizPresupuestoCliente;
end
else begin
APresupuestos : = Presupuestos;
end ;
ViewGrid. _Grid. BeginUpdate;
if Assigned( APresupuestos) then
begin
FController. CambiarSituacion( APresupuestos, SITUACION_PRESUPUESTO_ANULADO, AFecha, AllItems) ;
actRefrescar. Execute;
end ;
ViewGrid. _Grid. EndUpdate;
end ;
end ;
procedure TfEditorPresupuestosCliente. actAnularUpdate( Sender: TObject) ;
begin
inherited ;
( Sender as TAction) . Enabled : = HayDatos
and ViewGrid. esSeleccionCeldaDatos
and ( FPresupuestos. SITUACION < > SITUACION_PRESUPUESTO_ANULADO) ;
end ;
procedure TfEditorPresupuestosCliente. actEliminarUpdate( Sender: TObject) ;
begin
inherited ;
if ( Sender as TAction) . Enabled then
( Sender as TAction) . Enabled : = ( FPresupuestos. SITUACION = SITUACION_PRESUPUESTO_PENDIENTE) ;
end ;
procedure TfEditorPresupuestosCliente. actEnviarEMailExecute( Sender: TObject) ;
begin
inherited ;
FController. EnviarPresupuestoPorEMail( FPresupuestos) ;
end ;
procedure TfEditorPresupuestosCliente. actEnviarEMailUpdate( Sender: TObject) ;
begin
inherited ;
if HayDatos and Assigned( ViewGrid) then
( Sender as TAction) . Enabled : = ViewGrid. EsSeleccionCeldaDatos
and ( ViewGrid. NumSeleccionados > 0 )
else
( Sender as TAction) . Enabled : = False ;
end ;
procedure TfEditorPresupuestosCliente. actGenerarAlbaranCliExecute( Sender: TObject) ;
begin
inherited ;
GenerarAlbaranCli( FPresupuestos. ID) ;
end ;
procedure TfEditorPresupuestosCliente. actGenerarCertificadoExecute(
Sender: TObject) ;
var
APresupuestos: IBizPresupuestoCliente;
AllItems: Boolean ;
ATexto : String ;
begin
APresupuestos : = Nil ;
AllItems : = False ;
if MultiSelect and Assigned( ViewGrid) then
AllItems : = ( ViewGrid. NumSeleccionados > 1 ) ;
if AllItems then
begin
SeleccionarFilasDesdeGrid( ViewGrid. _FocusedView, ( Presupuestos as ISeleccionable) . SelectedRecords) ;
APresupuestos : = ( Controller as IPresupuestosClienteController) . ExtraerSeleccionados( Presupuestos) as IBizPresupuestoCliente;
ATexto : = 'Se han generado los certificados de trabajos.' ;
end
else begin
APresupuestos : = Presupuestos;
ATexto : = 'Se ha generado el certificado de trabajos.' ;
end ;
if Assigned( APresupuestos) then
if FController. GenerarCertificados( APresupuestos, AllItems) then
ShowInfoMessage( 'Generar certificado de trabajo' , ATexto)
end ;
procedure TfEditorPresupuestosCliente. actGenerarCertificadoUpdate(
Sender: TObject) ;
begin
( Sender as TAction) . Enabled : = HayDatos
and ViewGrid. EsSeleccionCeldaDatos
and ( FPresupuestos. SITUACION = SITUACION_PRESUPUESTO_ACEPTADO) ;
end ;
procedure TfEditorPresupuestosCliente. actGenerarExecute( Sender: TObject) ;
//var
// Respuesta : Integer;
begin
inherited ;
{
Respuesta : = JsGenerarDialog. Execute;
if Respuesta < > IDCANCEL then
begin
case JsGenerarDialog. CustomButtonResult of
2 0 0 : begin // Generar factura de cliente
actGenerarFactura. Execute;
end ;
1 0 0 : begin // Generar albaran de cliente
// actGenerarAlbaranCli.Execute;
end ;
end ;
actRefrescar. Execute;
end ;
}
end ;
procedure TfEditorPresupuestosCliente. actGenerarFacturaExecute( Sender: TObject) ;
begin
inherited ;
if ( ShowConfirmMessage( 'Generar factura' , Format( '<27> Desea copiar todos los conceptos del presupuesto %s a la factura?' , [ Presupuestos. REFERENCIA] ) ) = IDYES) then
GenerarFacturaCliPre( Presupuestos. ID)
else
GenerarFacturaCliPre( Presupuestos. ID, False ) ;
actRefrescar. Execute;
end ;
procedure TfEditorPresupuestosCliente. actGenerarFacturaUpdate( Sender: TObject) ;
begin
inherited ;
( Sender as TAction) . Enabled : = HayDatos
and not ( ViewGrid. NumSeleccionados > 1 )
and ( FPresupuestos. FACTURA = '' )
and ViewGrid. esSeleccionCeldaDatos
and ( FPresupuestos. SITUACION = SITUACION_PRESUPUESTO_ACEPTADO) ;
end ;
procedure TfEditorPresupuestosCliente. actGenerarPresupuestoProvExecute( Sender: TObject) ;
begin
inherited ;
// GenerarPresupuestosProv(FPresupuestos);
end ;
procedure TfEditorPresupuestosCliente. actInformesExecute( Sender: TObject) ;
var
Respuesta : Integer ;
AGestorInformesController : IGestorInformesController;
begin
AGestorInformesController : = TGestorInformesController. Create;
try
Respuesta : = JsInformesDialog. Execute;
if Respuesta < > IDCANCEL then
begin
case JsInformesDialog. CustomButtonResult of
1 0 0 : begin // Listado de facturas pendientes
AGestorInformesController. VerInformeListadoPresupuestos;
end ;
end ;
end ;
finally
AGestorInformesController : = NIL ;
end ;
end ;
procedure TfEditorPresupuestosCliente. AsignarVista;
begin
ViewGrid : = CreateView( TfrViewPresupuestosCliente) as IViewPresupuestosCliente;
end ;
constructor TfEditorPresupuestosCliente. Create( AOwner: TComponent) ;
begin
inherited ;
FHeaderText : = 'Lista de presupuestos de cliente' ;
FWindowCaption : = FHeaderText;
AsignarVista;
end ;
destructor TfEditorPresupuestosCliente. Destroy;
begin
FPresupuestos : = NIL ;
FController : = NIL ;
inherited ;
end ;
procedure TfEditorPresupuestosCliente. DuplicarInterno;
var
APresupuesto : IBizPresupuestoCliente;
begin
inherited ;
APresupuesto : = FController. Duplicar( Presupuestos) ;
try
FController. Ver( APresupuesto) ;
finally
actRefrescar. Execute;
end ;
end ;
procedure TfEditorPresupuestosCliente. EliminarInterno;
var
APresupuestos: IBizPresupuestoCliente;
AllItems: Boolean ;
begin
APresupuestos : = Nil ;
AllItems : = False ;
if MultiSelect and Assigned( ViewGrid) then
AllItems : = ( ViewGrid. NumSeleccionados > 1 ) ;
if AllItems then
begin
if ( Application. MessageBox( '<27> Desea borrar los presupuestos seleccionados?' , 'Atenci<63> n' , MB_YESNO) = IDYES) then
begin
SeleccionarFilasDesdeGrid( ViewGrid. _FocusedView, ( Presupuestos as ISeleccionable) . SelectedRecords) ;
APresupuestos : = ( Controller as IPresupuestosClienteController) . ExtraerSeleccionados( Presupuestos) as IBizPresupuestoCliente;
end
end
else begin
if ( Application. MessageBox( '<27> Desea borrar el presupuesto seleccionado?' , 'Atenci<63> n' , MB_YESNO) = IDYES) then
APresupuestos : = Presupuestos;
end ;
if Assigned( APresupuestos) then
begin
FController. Eliminar( APresupuestos, AllItems) ;
if AllItems then
begin
if ( APresupuestos. DataTable. RecordCount > 0 ) then
begin
with APresupuestos. DataTable do
begin
First;
while not EOF do
begin
JsListaPresupuestosNoEliminados. Content. Add( 'Ref. Presupuesto: ' + APresupuestos. REFERENCIA + ' ' + APresupuestos. NOMBRE) ;
Next;
end ;
end ;
JsListaPresupuestosNoEliminados. Execute;
end ;
actRefrescar. Execute;
end ;
end ;
ViewGrid. GotoFirst;
end ;
procedure TfEditorPresupuestosCliente. FormShow( Sender: TObject) ;
begin
cbxListaAnos. OnChange : = OnListaAnosChange; //OJO SIEMPRE ANTES DEL INHERITED
inherited ;
if not Assigned( ViewGrid) then
raise Exception. Create( 'No hay ninguna vista asignada' ) ;
if not Assigned( Presupuestos) then
raise Exception. Create( 'No hay ning<6E> n Presupuesto asignado' ) ;
Presupuestos. DataTable. Active : = True ;
ViewGrid. GotoFirst;
end ;
function TfEditorPresupuestosCliente. GetController: IPresupuestosClienteController;
begin
Result : = FController;
end ;
function TfEditorPresupuestosCliente. GetPresupuestos: IBizPresupuestoCliente;
begin
Result : = FPresupuestos;
end ;
procedure TfEditorPresupuestosCliente. ImprimirInterno;
var
Respuesta : Integer ;
APresupuestos: IBizPresupuestoCliente;
AllItems: Boolean ;
begin
APresupuestos : = 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
2 0 0 : begin // Lista de elementos visibles
inherited ;
end ;
1 0 0 : begin // Elemento Seleccionado
if AllItems then
begin
SeleccionarFilasDesdeGrid( ViewGrid. _FocusedView, ( Presupuestos as ISeleccionable) . SelectedRecords) ;
APresupuestos : = ( Controller as IPresupuestosClienteController) . ExtraerSeleccionados( Presupuestos) as IBizPresupuestoCliente;
end
else
APresupuestos : = Presupuestos;
if Assigned( APresupuestos) then
FController. Print( APresupuestos, AllItems) ;
end ;
end ;
end ;
end ;
end ;
procedure TfEditorPresupuestosCliente. ModificarInterno;
begin
inherited ;
FController. Ver( Presupuestos) ;
end ;
procedure TfEditorPresupuestosCliente. NuevoInterno;
begin
inherited ;
if FController. Anadir( Presupuestos) then
FController. Ver( Presupuestos) ;
end ;
2010-01-22 09:52:58 +00:00
procedure TfEditorPresupuestosCliente. OnListaAnosChange( Sender: TObject) ;
2009-12-16 17:16:54 +00:00
begin
2010-01-25 17:33:32 +00:00
Controller. FiltrarAno( Presupuestos, DynWhereDataTable, cbxListaAnos. Text ) ;
2009-12-16 17:16:54 +00:00
if Presupuestos. DataTable. Active then
RefrescarInterno;
end ;
procedure TfEditorPresupuestosCliente. PonerTitulos( const ATitulo: string ) ;
var
FTitulo : String ;
begin
FTitulo : = FWindowCaption + ' - ' + AppFactuGES. EmpresaActiva. NOMBRE;
inherited PonerTitulos( FTitulo) ;
end ;
procedure TfEditorPresupuestosCliente. PrevisualizarInterno;
var
Respuesta : Integer ;
APresupuestos: IBizPresupuestoCliente;
AllItems: Boolean ;
begin
APresupuestos : = 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
2 0 0 : begin // Lista de elementos visibles
inherited ;
end ;
1 0 0 : begin // Elemento Seleccionado
if AllItems then
begin
SeleccionarFilasDesdeGrid( ViewGrid. _FocusedView, ( Presupuestos as ISeleccionable) . SelectedRecords) ;
APresupuestos : = ( Controller as IPresupuestosClienteController) . ExtraerSeleccionados( Presupuestos) as IBizPresupuestoCliente;
end
else
APresupuestos : = Presupuestos;
if Assigned( APresupuestos) then
FController. Preview( APresupuestos, AllItems) ;
end ;
end ;
end ;
end ;
APresupuestos : = Nil ;
end ;
procedure TfEditorPresupuestosCliente. RefrescarInterno;
begin
//Volvemos a cargar los a<> os de los presupuestos
if Assigned( FController) then
ListaAnos : = FController. DarListaAnosPresupuestos;
inherited ;
end ;
procedure TfEditorPresupuestosCliente. SetController( const Value: IPresupuestosClienteController) ;
begin
FController : = Value;
if Assigned( FController) then
ListaAnos : = FController. DarListaAnosPresupuestos;
end ;
procedure TfEditorPresupuestosCliente. SetPresupuestos( const Value: IBizPresupuestoCliente) ;
begin
FPresupuestos : = Value;
if Assigned( FPresupuestos) then
begin
//Se guarda el where de la sentencia origen, por si el editor tiene filtros que
//afecten a este where y en un futuro se desea volver al where origen (filtro de a<> o))
DynWhereDataTable : = FPresupuestos. DataTable. DynamicWhere. Xml;
dsDataTable. DataTable : = FPresupuestos. DataTable;
if Assigned( ViewGrid) then
( ViewGrid as IViewPresupuestosCliente) . Presupuestos : = Presupuestos;
end ;
end ;
end .