2009-12-16 17:16:54 +00:00
unit uEditorAlbaranesCliente;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, 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,
uBizAlbaranesCliente, uIEditorAlbaranesCliente, uAlbaranesClienteController,
uCustomView, uViewBase, uViewBarraSeleccion, uViewGridBase,
2010-01-27 16:07:33 +00:00
uViewAlbaranesCliente, JvExComCtrls, JvStatusBar, JSDialog, uDAInterfaces,
StdCtrls, TntStdCtrls, SpTBXEditors;
2009-12-16 17:16:54 +00:00
type
TfEditorAlbaranesCliente = class( TfEditorGridBase, IEditorAlbaranesCliente)
JsNuevoAlbaranDialog: TJSDialog;
actGenerarFactura: TAction;
N4: TMenuItem;
Generarfactura1: TMenuItem;
2010-01-22 09:52:58 +00:00
TBXSeparatorItem17: TSpTBXSeparatorItem;
2009-12-16 17:16:54 +00:00
actEnviar: TAction;
Serviralbarn1: TMenuItem;
JsImprimirDialog: TJSDialog;
JsPrevisualizarDialog: TJSDialog;
actCancelarEnvio: TAction;
actConfirmarRecepcion: TAction;
2010-01-22 09:52:58 +00:00
TBXItem42: TSpTBXItem;
TBXItem43: TSpTBXItem;
TBXItem44: TSpTBXItem;
TBXSeparatorItem18: TSpTBXSeparatorItem;
TBXItem45: TSpTBXItem;
TBXSeparatorItem19: TSpTBXSeparatorItem;
2009-12-16 17:16:54 +00:00
actGenerarEtiquetas: TAction;
2010-01-22 09:52:58 +00:00
TBXItem38: TSpTBXItem;
2009-12-16 17:16:54 +00:00
JsListaAlbaranesNoEliminados: TJSDialog;
actEnviarEMail: TAction;
Enviarporemail1: TMenuItem;
2010-01-22 09:52:58 +00:00
TBXSubmenuItem2: TSpTBXSubmenuItem;
TBXItem39: TSpTBXItem;
2009-12-16 17:16:54 +00:00
procedure FormShow( Sender: TObject) ;
procedure actGenerarFacturaUpdate( Sender: TObject) ;
procedure actGenerarFacturaExecute( Sender: TObject) ;
procedure actEnviarUpdate( Sender: TObject) ;
procedure actEnviarExecute( Sender: TObject) ;
procedure actEliminarUpdate( Sender: TObject) ;
procedure actCancelarEnvioExecute( Sender: TObject) ;
procedure actCancelarEnvioUpdate( Sender: TObject) ;
procedure actConfirmarRecepcionExecute( Sender: TObject) ;
procedure actConfirmarRecepcionUpdate( Sender: TObject) ;
procedure actGenerarEtiquetasExecute( Sender: TObject) ;
procedure actGenerarEtiquetasUpdate( Sender: TObject) ;
procedure actEnviarEMailExecute( Sender: TObject) ;
procedure actEnviarEMailUpdate( Sender: TObject) ;
2010-01-22 09:52:58 +00:00
procedure OnListaAnosChange( Sender: TObject) ;
2009-12-16 17:16:54 +00:00
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 ;
procedure RefrescarInterno; 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, uFactuGES_App,
uGenerarFacturasCliAlbCliUtils,
2010-01-20 12:44:05 +00:00
//En noviseda no estaran habilitados los pedidos
2009-12-16 17:16:54 +00:00
// uPedidosClienteController, uBizPedidosCliente,
uDialogUtils, schAlbaranesClienteClient_Intf,
// uFacturasClienteController, uBizFacturasCliente,
// uInventarioController, uGenerarAlbaranesCliUtils,
uEditorBase,
cxCustomData, uGridStatusUtils, uDBSelectionListUtils;
{$R *.dfm}
{
* * * * * * * * * * * * * * * * * * * * * * * * * * * TfEditorAlbaranesCliente * * * * * * * * * * * * * * * * * * * * * * * * * * *
}
procedure TfEditorAlbaranesCliente. actCancelarEnvioExecute( Sender: TObject) ;
begin
{
inherited ;
if ( ShowConfirmMessage( 'Envío de albarán de cliente' , '¿Desea cancelar el envío de este albarán de cliente?' ) = IDYES) then
begin
try
FController. CambiarSituacion( FAlbaranes, SITUACION_ALBARAN_PENDIENTE) ;
except
on E : Exception do
ShowErrorMessage( 'Error al cambiar la situación del albarán' , E. Message , E) ;
end ;
end ;
actRefrescar. Execute;
}
end ;
procedure TfEditorAlbaranesCliente. actCancelarEnvioUpdate( Sender: TObject) ;
begin
inherited ;
( Sender as TAction) . Enabled : = HayDatos
and not ( ViewGrid. NumSeleccionados > 1 )
and ViewGrid. esSeleccionCeldaDatos
and ( FAlbaranes. SITUACION = SITUACION_ALBARAN_ENVIADO) ;
end ;
procedure TfEditorAlbaranesCliente. actConfirmarRecepcionExecute( Sender: TObject) ;
begin
{
inherited ;
try
FController. CambiarSituacion( FAlbaranes, SITUACION_ALBARAN_SERVIDO, FAlbaranes. FECHA_ENVIO, Now) ;
except
on E : Exception do
ShowErrorMessage( 'Error al cambiar la situación del albarán' , E. Message , E) ;
end ;
actRefrescar. Execute;
}
end ;
procedure TfEditorAlbaranesCliente. actConfirmarRecepcionUpdate( Sender: TObject) ;
begin
inherited ;
( Sender as TAction) . Enabled : = HayDatos
and not ( ViewGrid. NumSeleccionados > 1 )
and ViewGrid. esSeleccionCeldaDatos
and ( FAlbaranes. SITUACION = SITUACION_ALBARAN_ENVIADO) ;
end ;
procedure TfEditorAlbaranesCliente. actEliminarUpdate( Sender: TObject) ;
begin
inherited ;
if ( Sender as TAction) . Enabled
and ( FAlbaranes. TIPO = CTE_TIPO_ALBARAN) then
( Sender as TAction) . Enabled : = not ( FAlbaranes. ID_FACTURA > 0 )
and ( FAlbaranes. SITUACION = SITUACION_ALBARAN_PENDIENTE)
end ;
procedure TfEditorAlbaranesCliente. actGenerarEtiquetasExecute( Sender: TObject) ;
begin
{
inherited ;
//Miramos si viene de un pedido previo, si no es asi le preguntamos si desea imprimir la referencia del cliente
if ( FAlbaranes. ID_PEDIDO > 0 ) then
FController. EtiquetasPreview( FAlbaranes, True )
else
begin
if ( Application. MessageBox( '¿El albarán seleccionado no está asociado a un pedido por internet, ¿desea imprimir la referencia del cliente para las etiquetas de este albarán?' , 'Atención' , MB_YESNO) = IDYES) then
FController. EtiquetasPreview( FAlbaranes, True )
else
FController. EtiquetasPreview( FAlbaranes, False ) ;
end ;
}
end ;
procedure TfEditorAlbaranesCliente. actGenerarEtiquetasUpdate( Sender: TObject) ;
begin
inherited ;
( Sender as TAction) . Enabled : = HayDatos
and not ( ViewGrid. NumSeleccionados > 1 )
and ViewGrid. esSeleccionCeldaDatos;
end ;
procedure TfEditorAlbaranesCliente. actGenerarFacturaExecute( Sender: TObject) ;
begin
GenerarFacturaCliAlb( Albaranes. ID) ;
actRefrescar. Execute;
end ;
procedure TfEditorAlbaranesCliente. actGenerarFacturaUpdate( Sender: TObject) ;
begin
inherited ;
( Sender as TAction) . Enabled : = HayDatos
and not ( ViewGrid. NumSeleccionados > 1 )
and ( FAlbaranes. REF_FACTURA = '' )
and ViewGrid. esSeleccionCeldaDatos;
end ;
procedure TfEditorAlbaranesCliente. actEnviarEMailExecute( Sender: TObject) ;
begin
inherited ;
FController. EnviarAlbaranPorEMail( FAlbaranes) ;
end ;
procedure TfEditorAlbaranesCliente. 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 TfEditorAlbaranesCliente. actEnviarExecute( Sender: TObject) ;
//var
// AInventarioController : IInventarioController;
// bCambiarEstado : Boolean;
// AFactura : IBizFacturaCliente;
// AFacturasController : IFacturasClienteController;
// AAlbaran : IBizAlbaranCliente;
begin
{
inherited ;
bCambiarEstado : = False ;
// ¿Hay almacén asociado al albarán?
if FAlbaranes. ID_ALMACEN = 0 then
begin
if ( ShowConfirmMessage( 'Envío de albarán de cliente' , 'Este albarán no tiene un almacén asociado por lo que no se realizará ningún cambio en el stock de los almacenes.'
+ #10 #13 + #10 #13 + '¿Desea realizar el envío de este albarán de cliente?' ) = IDYES) then
bCambiarEstado : = True // No hay almacén. Cambiamos el estado y ya está.
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án de cliente. ¿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ón del albarán' , E. Message , E) ;
end ;
end ;
actRefrescar. Execute;
}
end ;
procedure TfEditorAlbaranesCliente. actEnviarUpdate( Sender: TObject) ;
begin
inherited ;
( Sender as TAction) . Enabled : = HayDatos
and not ( ViewGrid. NumSeleccionados > 1 )
and ViewGrid. esSeleccionCeldaDatos
and ( FAlbaranes. SITUACION = SITUACION_ALBARAN_PENDIENTE) ;
end ;
procedure TfEditorAlbaranesCliente. AsignarVista;
begin
ViewGrid : = CreateView( TfrViewAlbaranesCliente) as IViewAlbaranesCliente;
end ;
constructor TfEditorAlbaranesCliente. Create( AOwner: TComponent) ;
begin
inherited ;
FHeaderText : = 'Lista de albaranes de cliente' ;
FWindowCaption : = FHeaderText;
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;
var
AAlbaranes: IBizAlbaranCliente;
AllItems: Boolean ;
begin
AAlbaranes : = Nil ;
AllItems : = False ;
if MultiSelect and Assigned( ViewGrid) then
AllItems : = ( ViewGrid. NumSeleccionados > 1 ) ;
if AllItems then
begin
if ( Application. MessageBox( '¿Desea borrar los albaranes de cliente seleccionados?' , 'Atención' , MB_YESNO) = IDYES) then
begin
SeleccionarFilasDesdeGrid( ViewGrid. _FocusedView, ( Albaranes as ISeleccionable) . SelectedRecords) ;
AAlbaranes : = ( Controller as IAlbaranesClienteController) . ExtraerSeleccionados( Albaranes) as IBizAlbaranCliente;
end
end
else begin
if ( Application. MessageBox( '¿Desea borrar el albarán de cliente seleccionado?' , 'Atención' , MB_YESNO) = IDYES) then
AAlbaranes : = Albaranes;
end ;
if Assigned( AAlbaranes) then
begin
FController. Eliminar( AAlbaranes, AllItems) ;
if AllItems then
begin
if ( AAlbaranes. DataTable. RecordCount > 0 ) then
begin
with AAlbaranes. DataTable do
begin
First;
while not EOF do
begin
JsListaAlbaranesNoEliminados. Content. Add( 'Ref. albarán: ' + AAlbaranes. REFERENCIA + ' ' + AAlbaranes. NOMBRE) ;
Next;
end ;
end ;
JsListaAlbaranesNoEliminados. Execute;
end ;
actRefrescar. Execute;
end ;
end ;
ViewGrid. GotoFirst;
end ;
procedure TfEditorAlbaranesCliente. 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( Albaranes) then
raise Exception. Create( 'No hay ningún albará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;
var
Respuesta : Integer ;
AAlbaranes: IBizAlbaranCliente;
AllItems: Boolean ;
begin
AAlbaranes : = Nil ;
AllItems : = False ;
if MultiSelect and Assigned( ViewGrid) then
AllItems : = ( ViewGrid. NumSeleccionados > 1 ) ;
//Si esta agrupado solo podré 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
2010-01-27 16:51:02 +00:00
3 0 0 : begin // Lista de elementos visibles
if AllItems then
begin
SeleccionarFilasDesdeGrid( ViewGrid. _FocusedView, ( Albaranes as ISeleccionable) . SelectedRecords) ;
AAlbaranes : = ( Controller as IAlbaranesClienteController) . ExtraerSeleccionados( Albaranes) as IBizAlbaranCliente;
end
else
AAlbaranes : = Albaranes;
if Assigned( AAlbaranes) then
FController. EtiquetasPrint( AAlbaranes, AllItems) ;
end ;
2009-12-16 17:16:54 +00:00
2 0 0 : begin // Lista de elementos visibles
inherited ;
end ;
1 0 0 : begin // Elemento Seleccionado
if AllItems then
begin
SeleccionarFilasDesdeGrid( ViewGrid. _FocusedView, ( Albaranes as ISeleccionable) . SelectedRecords) ;
AAlbaranes : = ( Controller as IAlbaranesClienteController) . ExtraerSeleccionados( Albaranes) as IBizAlbaranCliente;
end
else
AAlbaranes : = Albaranes;
if Assigned( AAlbaranes) then
FController. Print( AAlbaranes, AllItems) ;
end ;
end ;
end ;
end ;
end ;
procedure TfEditorAlbaranesCliente. ModificarInterno;
begin
inherited ;
FController. Ver( Albaranes) ;
end ;
procedure TfEditorAlbaranesCliente. NuevoInterno;
{ var
Respuesta : Integer ;
AAlbaran : IBizAlbaranCliente;
IDAlbaranAux: Integer ; }
begin
inherited ;
// Respuesta := JsNuevoAlbaranDialog.Execute;
// if Respuesta <> IDCANCEL then
// begin
// case JsNuevoAlbaranDialog.CustomButtonResult of
// 200 : begin // Utilizar un pedido
// if ElegirPedidoYGenerarAlbaranCli(IDAlbaranAux) then
// actRefrescar.Execute;
// end;
// 100 : begin // Albaran nuevo vacio
if FController. Anadir( Albaranes) then
FController. Ver( Albaranes) ;
// end;
// end;
// end;
end ;
2010-01-22 09:52:58 +00:00
procedure TfEditorAlbaranesCliente. OnListaAnosChange( Sender: TObject) ;
2009-12-16 17:16:54 +00:00
begin
2010-01-25 17:33:32 +00:00
Controller. FiltrarAno( Albaranes, DynWhereDataTable, cbxListaAnos. Text ) ;
2009-12-16 17:16:54 +00:00
if Albaranes. DataTable. Active then
RefrescarInterno;
end ;
procedure TfEditorAlbaranesCliente. PonerTitulos( const ATitulo: string ) ;
var
FTitulo : String ;
begin
FTitulo : = FWindowCaption + ' - ' + AppFactuGES. EmpresaActiva. NOMBRE;
inherited PonerTitulos( FTitulo) ;
end ;
procedure TfEditorAlbaranesCliente. PrevisualizarInterno;
var
Respuesta : Integer ;
AAlbaranes: IBizAlbaranCliente;
AllItems: Boolean ;
begin
AAlbaranes : = Nil ;
AllItems : = False ;
if MultiSelect and Assigned( ViewGrid) then
AllItems : = ( ViewGrid. NumSeleccionados > 1 ) ;
//Si esta agrupado solo podré 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
2010-01-27 16:07:33 +00:00
3 0 0 : begin // Lista de elementos visibles
if AllItems then
begin
SeleccionarFilasDesdeGrid( ViewGrid. _FocusedView, ( Albaranes as ISeleccionable) . SelectedRecords) ;
AAlbaranes : = ( Controller as IAlbaranesClienteController) . ExtraerSeleccionados( Albaranes) as IBizAlbaranCliente;
end
else
AAlbaranes : = Albaranes;
if Assigned( AAlbaranes) then
2010-01-27 16:51:02 +00:00
FController. EtiquetasPreview( AAlbaranes, AllItems) ;
2010-01-27 16:07:33 +00:00
end ;
2009-12-16 17:16:54 +00:00
2 0 0 : begin // Lista de elementos visibles
inherited ;
end ;
1 0 0 : begin // Elemento Seleccionado
if AllItems then
begin
SeleccionarFilasDesdeGrid( ViewGrid. _FocusedView, ( Albaranes as ISeleccionable) . SelectedRecords) ;
AAlbaranes : = ( Controller as IAlbaranesClienteController) . ExtraerSeleccionados( Albaranes) as IBizAlbaranCliente;
end
else
AAlbaranes : = Albaranes;
if Assigned( AAlbaranes) then
FController. Preview( AAlbaranes, AllItems) ;
end ;
end ;
end ;
end ;
end ;
procedure TfEditorAlbaranesCliente. RefrescarInterno;
begin
//Volvemos a cargar los años de los albaranes
if Assigned( FController) then
ListaAnos : = FController. DarListaAnosAlbaranes;
inherited ;
end ;
procedure TfEditorAlbaranesCliente. SetController( const Value: IAlbaranesClienteController) ;
begin
FController : = Value;
if Assigned( FController) then
ListaAnos : = FController. DarListaAnosAlbaranes;
end ;
procedure TfEditorAlbaranesCliente. SetAlbaranes( const Value: IBizAlbaranCliente) ;
begin
FAlbaranes : = Value;
if Assigned( FAlbaranes) 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 : = FAlbaranes. DataTable. DynamicWhere. Xml;
dsDataTable. DataTable : = FAlbaranes. DataTable;
if Assigned( ViewGrid) then
( ViewGrid as IViewAlbaranesCliente) . Albaranes : = Albaranes;
end ;
end ;
end .