437 lines
14 KiB
ObjectPascal
437 lines
14 KiB
ObjectPascal
|
|
unit uEditorContratoCliente;
|
|||
|
|
|
|||
|
|
interface
|
|||
|
|
|
|||
|
|
uses
|
|||
|
|
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
|
|||
|
|
uEditorDBItem, DB, uDADataTable, JvAppStorage,
|
|||
|
|
JvAppRegistryStorage, JvComponent, JvFormPlacement, ImgList,
|
|||
|
|
PngImageList, StdActns, ActnList, ComCtrls, TBX, TB2Item, TB2Dock,
|
|||
|
|
TB2Toolbar, ExtCtrls, JvExControls, JvNavigationPane,
|
|||
|
|
uCustomView, uViewBase, JvComponentBase,
|
|||
|
|
StdCtrls, pngimage, AppEvnts, cxControls, cxContainer, cxEdit, cxTextEdit, cxMemo, cxDBEdit,
|
|||
|
|
uViewIncidencias,
|
|||
|
|
uContratosClienteController,
|
|||
|
|
uViewDetallesBase,
|
|||
|
|
dxLayoutLookAndFeels, JvExComCtrls, JvStatusBar, uViewTotales,
|
|||
|
|
uIEditorContratoCliente, uBizContratosCliente, uViewContratoCliente,
|
|||
|
|
uViewDetallesDTO, uViewDetallesArticulos, uViewDetallesContratoCliente,
|
|||
|
|
uDAInterfaces, cxRichEdit, cxDBRichEdit, JvGIF, cxPC,
|
|||
|
|
uViewDocumentos,
|
|||
|
|
uViewDocumentosContratoCliente, uViewDatosYSeleccionClienteContrato,
|
|||
|
|
cxLabel, uBizTiposIVA, uTiposIVAController;
|
|||
|
|
|
|||
|
|
type
|
|||
|
|
TfEditorContratoCliente = class(TfEditorDBItem, IEditorContratoCliente)
|
|||
|
|
pagContenido: TTabSheet;
|
|||
|
|
pagInicidencias: TTabSheet;
|
|||
|
|
frViewIncidenciasCli: TfrViewIncidencias;
|
|||
|
|
dxLayoutLookAndFeelList1: TdxLayoutLookAndFeelList;
|
|||
|
|
dxLayoutOfficeLookAndFeel1: TdxLayoutOfficeLookAndFeel;
|
|||
|
|
TBXSubmenuItem2: TTBXSubmenuItem;
|
|||
|
|
TBXItem7: TTBXItem;
|
|||
|
|
TBXSeparatorItem6: TTBXSeparatorItem;
|
|||
|
|
actEnviarPorEMail: TAction;
|
|||
|
|
TBXItem34: TTBXItem;
|
|||
|
|
TBXItem35: TTBXItem;
|
|||
|
|
pagDocumentos: TTabSheet;
|
|||
|
|
frViewDocumentosContratoCliente1: TfrViewDocumentosContratoCliente;
|
|||
|
|
frViewTotales1: TfrViewTotales;
|
|||
|
|
frViewDetallesContratoCliente1: TfrViewDetallesContratoCliente;
|
|||
|
|
|
|||
|
|
procedure FormShow(Sender: TObject);
|
|||
|
|
procedure CustomEditorClose(Sender: TObject; var Action: TCloseAction);
|
|||
|
|
procedure frViewTotales1ePortePropertiesValidate(Sender: TObject;
|
|||
|
|
var DisplayValue: Variant; var ErrorText: TCaption; var Error: Boolean);
|
|||
|
|
procedure pgPaginasChanging(Sender: TObject; var AllowChange: Boolean);
|
|||
|
|
procedure actEnviarPorEMailExecute(Sender: TObject);
|
|||
|
|
procedure actEnviarPorEMailUpdate(Sender: TObject);
|
|||
|
|
procedure actEliminarUpdate(Sender: TObject);
|
|||
|
|
procedure frViewTotales1bTiposIVAClick(Sender: TObject);
|
|||
|
|
procedure frViewTotales1eIVAPropertiesValidate(Sender: TObject;
|
|||
|
|
var DisplayValue: Variant; var ErrorText: TCaption; var Error: Boolean);
|
|||
|
|
procedure OnRecargoEquivalenciaPropertiesValidate(Sender: TObject; var DisplayValue: Variant; var ErrorText: TCaption;
|
|||
|
|
var Error: Boolean); //Importante en este punto se deben de quitar los eventos que puedan afectar a la tabla una vez se cierre el editor.
|
|||
|
|
|
|||
|
|
private
|
|||
|
|
//procedure RecalcularPortePorUnidad;
|
|||
|
|
|
|||
|
|
protected
|
|||
|
|
FContrato: IBizContratoCliente;
|
|||
|
|
FTiposIVAController : ITiposIVAController;
|
|||
|
|
FTiposIVA: IBizTipoIVA;
|
|||
|
|
FViewContrato: IViewContratoCliente;
|
|||
|
|
FViewClienteContrato :IViewDatosYSeleccionClienteContrato;
|
|||
|
|
FController : IContratosClienteController;
|
|||
|
|
|
|||
|
|
function GetController : IContratosClienteController;
|
|||
|
|
procedure SetController (const Value : IContratosClienteController); virtual;
|
|||
|
|
|
|||
|
|
function GetContrato: IBizContratoCliente;
|
|||
|
|
procedure SetContrato(const Value: IBizContratoCliente); virtual;
|
|||
|
|
|
|||
|
|
function GetViewContrato: IViewContratoCliente;
|
|||
|
|
procedure SetViewContrato(const Value: IViewContratoCliente);
|
|||
|
|
|
|||
|
|
procedure PrevisualizarInterno; override;
|
|||
|
|
procedure ImprimirInterno; override;
|
|||
|
|
procedure GuardarInterno; override;
|
|||
|
|
procedure EliminarInterno; override;
|
|||
|
|
|
|||
|
|
property ViewContrato: IViewContratoCliente read GetViewContrato write SetViewContrato;
|
|||
|
|
|
|||
|
|
procedure OnClienteChanged(Sender : TObject);
|
|||
|
|
|
|||
|
|
//Si queremos crear otra vista para el editor heredado solo tendriamos que
|
|||
|
|
//sobreescribir este metodo
|
|||
|
|
procedure AsignarVista; virtual;
|
|||
|
|
|
|||
|
|
procedure PonerTitulos(const ATitulo: string = ''); override;
|
|||
|
|
function GetModified: Boolean; override;
|
|||
|
|
procedure SetModified(const Value : Boolean); override;
|
|||
|
|
|
|||
|
|
function PuedoImprimir: Boolean; override;
|
|||
|
|
|
|||
|
|
public
|
|||
|
|
property Controller : IContratosClienteController read GetController write SetController;
|
|||
|
|
property Contrato: IBizContratoCliente read GetContrato write SetContrato;
|
|||
|
|
constructor Create(AOwner: TComponent); override;
|
|||
|
|
destructor Destroy; override;
|
|||
|
|
end;
|
|||
|
|
|
|||
|
|
implementation
|
|||
|
|
|
|||
|
|
uses
|
|||
|
|
uViewDatosYSeleccionCliente, uDataModuleUsuarios, uClientesController,
|
|||
|
|
uBizDireccionesContacto, uDialogUtils, uFactuGES_App, uDataTableUtils;
|
|||
|
|
|
|||
|
|
{$R *.dfm}
|
|||
|
|
|
|||
|
|
{ TfEditorContratoCliente }
|
|||
|
|
|
|||
|
|
{
|
|||
|
|
**************************** TfEditorContratoCliente ****************************
|
|||
|
|
}
|
|||
|
|
procedure TfEditorContratoCliente.actEliminarUpdate(Sender: TObject);
|
|||
|
|
begin
|
|||
|
|
inherited;
|
|||
|
|
if (Sender as TAction).Enabled then
|
|||
|
|
(Sender as TAction).Enabled := (FContrato.SITUACION = SITUACION_Contrato_PENDIENTE);
|
|||
|
|
end;
|
|||
|
|
|
|||
|
|
procedure TfEditorContratoCliente.actEnviarPorEMailExecute(Sender: TObject);
|
|||
|
|
begin
|
|||
|
|
inherited;
|
|||
|
|
FController.EnviarContratoPorEMail(Contrato);
|
|||
|
|
end;
|
|||
|
|
|
|||
|
|
procedure TfEditorContratoCliente.actEnviarPorEMailUpdate(Sender: TObject);
|
|||
|
|
begin
|
|||
|
|
inherited;
|
|||
|
|
(Sender as TAction).Enabled := HayDatos;
|
|||
|
|
end;
|
|||
|
|
|
|||
|
|
procedure TfEditorContratoCliente.AsignarVista;
|
|||
|
|
var
|
|||
|
|
AViewContratoCliente: TfrViewContratoCliente;
|
|||
|
|
|
|||
|
|
begin
|
|||
|
|
AViewContratoCliente := TfrViewContratoCliente.create(Self);
|
|||
|
|
with AViewContratoCliente do
|
|||
|
|
begin
|
|||
|
|
Parent := pagGeneral;
|
|||
|
|
Align := alClient;
|
|||
|
|
dxLayoutControl1.LookAndFeel := dxLayoutOfficeLookAndFeel1;
|
|||
|
|
end;
|
|||
|
|
ViewContrato := AViewContratoCliente;
|
|||
|
|
end;
|
|||
|
|
|
|||
|
|
constructor TfEditorContratoCliente.Create(AOwner: TComponent);
|
|||
|
|
begin
|
|||
|
|
inherited;
|
|||
|
|
pgPaginas.ActivePageIndex := 0;
|
|||
|
|
AsignarVista;
|
|||
|
|
|
|||
|
|
FTiposIVAController := TTiposIVAController.Create;
|
|||
|
|
end;
|
|||
|
|
|
|||
|
|
procedure TfEditorContratoCliente.CustomEditorClose(Sender: TObject;
|
|||
|
|
var Action: TCloseAction);
|
|||
|
|
begin
|
|||
|
|
inherited;
|
|||
|
|
//GESTION_DOCUMENTOS
|
|||
|
|
//Este m<>todo eliminar<61> el directorio temporal si se ha creado
|
|||
|
|
frViewDocumentosContratoCliente1.actEliminarTodo.Execute;
|
|||
|
|
|
|||
|
|
FViewContrato := NIL;
|
|||
|
|
FViewClienteContrato := NIL;
|
|||
|
|
FContrato := NIL;
|
|||
|
|
FTiposIVAController := Nil;
|
|||
|
|
end;
|
|||
|
|
|
|||
|
|
destructor TfEditorContratoCliente.Destroy;
|
|||
|
|
begin
|
|||
|
|
// Utilizar mejor OnClose;
|
|||
|
|
inherited;
|
|||
|
|
end;
|
|||
|
|
|
|||
|
|
procedure TfEditorContratoCliente.EliminarInterno;
|
|||
|
|
begin
|
|||
|
|
if (ShowConfirmMessage('<27>Desea borrar este Contrato de cliente?', '') = IDYES) then
|
|||
|
|
begin
|
|||
|
|
FController.Eliminar(FContrato);
|
|||
|
|
inherited
|
|||
|
|
end
|
|||
|
|
end;
|
|||
|
|
|
|||
|
|
procedure TfEditorContratoCliente.FormShow(Sender: TObject);
|
|||
|
|
begin
|
|||
|
|
inherited;
|
|||
|
|
|
|||
|
|
if not Assigned(FViewContrato) then
|
|||
|
|
raise Exception.Create('No hay ninguna vista asignada');
|
|||
|
|
|
|||
|
|
if not Assigned(Contrato) then
|
|||
|
|
raise Exception.Create('No hay ning<6E>n Contrato asignado');
|
|||
|
|
|
|||
|
|
frViewTotales1.cbRecargoEquivalencia.Properties.OnValidate := OnRecargoEquivalenciaPropertiesValidate;
|
|||
|
|
|
|||
|
|
pgPaginas.ActivePage := pagGeneral;
|
|||
|
|
Contrato.DataTable.Active := True;
|
|||
|
|
end;
|
|||
|
|
|
|||
|
|
procedure TfEditorContratoCliente.frViewTotales1bTiposIVAClick(
|
|||
|
|
Sender: TObject);
|
|||
|
|
begin
|
|||
|
|
inherited;
|
|||
|
|
FTiposIVAController.VerTodos(FTiposIVA);
|
|||
|
|
end;
|
|||
|
|
|
|||
|
|
procedure TfEditorContratoCliente.frViewTotales1eIVAPropertiesValidate(
|
|||
|
|
Sender: TObject; var DisplayValue: Variant; var ErrorText: TCaption;
|
|||
|
|
var Error: Boolean);
|
|||
|
|
begin
|
|||
|
|
inherited;
|
|||
|
|
Contrato.Edit;
|
|||
|
|
Contrato.ID_TIPO_IVA := FTiposIVA.ID; // ((frViewTotales1.dsTiposIVA.DataTable) as IBizTipoIVA).ID;
|
|||
|
|
end;
|
|||
|
|
|
|||
|
|
procedure TfEditorContratoCliente.frViewTotales1ePortePropertiesValidate(
|
|||
|
|
Sender: TObject; var DisplayValue: Variant; var ErrorText: TCaption;
|
|||
|
|
var Error: Boolean);
|
|||
|
|
begin
|
|||
|
|
inherited;
|
|||
|
|
{ if (not VarIsNull(DisplayValue)) and (Length(DisplayValue) > 0) then
|
|||
|
|
FContrato.IMPORTE_PORTE := DisplayValue
|
|||
|
|
else
|
|||
|
|
FContrato.IMPORTE_PORTE := 0;
|
|||
|
|
}
|
|||
|
|
// RecalcularPortePorUnidad; En los documentos de cliente no se desglosa el porte por articulo
|
|||
|
|
end;
|
|||
|
|
|
|||
|
|
function TfEditorContratoCliente.GetController: IContratosClienteController;
|
|||
|
|
begin
|
|||
|
|
Result := FController;
|
|||
|
|
end;
|
|||
|
|
|
|||
|
|
function TfEditorContratoCliente.GetModified: Boolean;
|
|||
|
|
begin
|
|||
|
|
// inherited; <- No llamar al padre porque queremos tratamiento especial.
|
|||
|
|
if ReadOnly then
|
|||
|
|
Result := False
|
|||
|
|
else begin
|
|||
|
|
Result := DataTableModified(dsDataTable.DataTable);
|
|||
|
|
|
|||
|
|
if not Result then
|
|||
|
|
Result := frViewDocumentosContratoCliente1.Modified;
|
|||
|
|
end;
|
|||
|
|
end;
|
|||
|
|
|
|||
|
|
function TfEditorContratoCliente.GetContrato: IBizContratoCliente;
|
|||
|
|
begin
|
|||
|
|
Result := FContrato;
|
|||
|
|
end;
|
|||
|
|
|
|||
|
|
function TfEditorContratoCliente.GetViewContrato: IViewContratoCliente;
|
|||
|
|
begin
|
|||
|
|
Result := FViewContrato;
|
|||
|
|
end;
|
|||
|
|
|
|||
|
|
procedure TfEditorContratoCliente.GuardarInterno;
|
|||
|
|
var
|
|||
|
|
bEsNuevo : Boolean;
|
|||
|
|
begin
|
|||
|
|
inherited;
|
|||
|
|
|
|||
|
|
ShowHourglassCursor;
|
|||
|
|
// frViewDetallesContratoCliente1.SaveGridStatus;
|
|||
|
|
frViewDetallesContratoCliente1.BeginUpdate;
|
|||
|
|
try
|
|||
|
|
bEsNuevo := FContrato.EsNuevo;
|
|||
|
|
//GESTION_DOCUMENTOS
|
|||
|
|
if FController.Guardar(FContrato) then
|
|||
|
|
frViewDocumentosContratoCliente1.actActualizarServidor.Execute;
|
|||
|
|
|
|||
|
|
finally
|
|||
|
|
frViewDetallesContratoCliente1.EndUpdate;
|
|||
|
|
// frViewDetallesContratoCliente1.RestoreGridStatus;
|
|||
|
|
HideHourglassCursor;
|
|||
|
|
end;
|
|||
|
|
if bEsNuevo then
|
|||
|
|
ShowInfoMessage('El Contrato se ha dado de alta con el c<>digo ' + FContrato.REFERENCIA);
|
|||
|
|
|
|||
|
|
Modified := False;
|
|||
|
|
end;
|
|||
|
|
|
|||
|
|
procedure TfEditorContratoCliente.ImprimirInterno;
|
|||
|
|
begin
|
|||
|
|
inherited;
|
|||
|
|
if not Modified then
|
|||
|
|
FController.Print(FContrato);
|
|||
|
|
end;
|
|||
|
|
|
|||
|
|
procedure TfEditorContratoCliente.OnClienteChanged(Sender: TObject);
|
|||
|
|
begin
|
|||
|
|
if Assigned(FContrato) then
|
|||
|
|
begin
|
|||
|
|
FContrato.Cliente := ViewContrato.ViewClienteContrato.Cliente;
|
|||
|
|
|
|||
|
|
//Desactivado porque en Contratos no utilizan el cat<61>logo de clientes
|
|||
|
|
// if (FContrato.Detalles.RecordCount > 0) then
|
|||
|
|
// FController.DetallesController.ActualizarDetalles(FContrato.Detalles, FContrato.Cliente);
|
|||
|
|
end;
|
|||
|
|
end;
|
|||
|
|
|
|||
|
|
procedure TfEditorContratoCliente.OnRecargoEquivalenciaPropertiesValidate(
|
|||
|
|
Sender: TObject; var DisplayValue: Variant; var ErrorText: TCaption;
|
|||
|
|
var Error: Boolean);
|
|||
|
|
begin
|
|||
|
|
|
|||
|
|
if frViewTotales1.cbRecargoEquivalencia.Checked then
|
|||
|
|
Contrato.RECARGO_EQUIVALENCIA := 1
|
|||
|
|
else
|
|||
|
|
Contrato.RECARGO_EQUIVALENCIA := 0;
|
|||
|
|
end;
|
|||
|
|
|
|||
|
|
procedure TfEditorContratoCliente.pgPaginasChanging(Sender: TObject;
|
|||
|
|
var AllowChange: Boolean);
|
|||
|
|
var
|
|||
|
|
ACadena : String;
|
|||
|
|
begin
|
|||
|
|
inherited;
|
|||
|
|
if (not Assigned(FContrato)) or (FContrato.ID_CLIENTE = 0) then
|
|||
|
|
begin
|
|||
|
|
ACadena := 'Antes de introducir conceptos debe elegir un cliente para este Contrato';
|
|||
|
|
ShowWarningMessage(ACadena);
|
|||
|
|
AllowChange := False;
|
|||
|
|
end
|
|||
|
|
end;
|
|||
|
|
|
|||
|
|
procedure TfEditorContratoCliente.PonerTitulos(const ATitulo: string);
|
|||
|
|
var
|
|||
|
|
FTitulo : String;
|
|||
|
|
begin
|
|||
|
|
FTitulo := ATitulo;
|
|||
|
|
if (FTitulo = '') and Assigned(FContrato) then
|
|||
|
|
begin
|
|||
|
|
if FContrato.EsNuevo then
|
|||
|
|
FTitulo := 'Nuevo Contrato de cliente'
|
|||
|
|
else
|
|||
|
|
FTitulo := 'Contrato de cliente' + ' - ' + FContrato.Cliente.Nombre + ' - ' + FContrato.SITUACION;
|
|||
|
|
end;
|
|||
|
|
|
|||
|
|
inherited PonerTitulos(FTitulo);
|
|||
|
|
Self.Caption := FTitulo + ' (' + AppFactuGES.EmpresaActiva.NOMBRE + ')';
|
|||
|
|
end;
|
|||
|
|
|
|||
|
|
procedure TfEditorContratoCliente.PrevisualizarInterno;
|
|||
|
|
begin
|
|||
|
|
inherited;
|
|||
|
|
if not Modified then
|
|||
|
|
FController.Preview(FContrato);
|
|||
|
|
end;
|
|||
|
|
|
|||
|
|
{procedure TfEditorContratoCliente.RecalcularPortePorUnidad;
|
|||
|
|
begin
|
|||
|
|
//Esta l<>gica se llamar<61> en el editor porque es para facilitar el rellenado de informaci<63>n del documento
|
|||
|
|
//no puede ir en la clase de negocio porque no es una l<>gica que tenga sentido fuera del editor.
|
|||
|
|
if Assigned(Controller)
|
|||
|
|
and Assigned(Controller.DetallesController) then
|
|||
|
|
Controller.DetallesController.DesglosarPorteDetalles(FContrato.IMPORTE_PORTE, FContrato.Detalles)
|
|||
|
|
end;}
|
|||
|
|
|
|||
|
|
procedure TfEditorContratoCliente.SetController(const Value: IContratosClienteController);
|
|||
|
|
begin
|
|||
|
|
FController := Value;
|
|||
|
|
|
|||
|
|
if Assigned(FController) then
|
|||
|
|
begin
|
|||
|
|
// ViewContrato.ViewClienteContrato.Controller := Controller.ClienteController;
|
|||
|
|
frViewDetallesContratoCliente1.Controller := Controller.DetallesController;
|
|||
|
|
|
|||
|
|
//GESTION_DOCUMENTOS
|
|||
|
|
frViewDocumentosContratoCliente1.Controller := Controller;
|
|||
|
|
|
|||
|
|
// frViewTotales1.Controller := FController;
|
|||
|
|
end;
|
|||
|
|
end;
|
|||
|
|
|
|||
|
|
procedure TfEditorContratoCliente.SetModified(const Value: Boolean);
|
|||
|
|
begin
|
|||
|
|
inherited;
|
|||
|
|
frViewDocumentosContratoCliente1.Modified := Value;
|
|||
|
|
end;
|
|||
|
|
|
|||
|
|
function TfEditorContratoCliente.PuedoImprimir: Boolean;
|
|||
|
|
begin
|
|||
|
|
Result := inherited PuedoImprimir and (not Contrato.Cliente.IDIsNull);
|
|||
|
|
end;
|
|||
|
|
|
|||
|
|
procedure TfEditorContratoCliente.SetContrato(const Value: IBizContratoCliente);
|
|||
|
|
begin
|
|||
|
|
FContrato := Value;
|
|||
|
|
|
|||
|
|
if Assigned(FContrato) then
|
|||
|
|
begin
|
|||
|
|
dsDataTable.DataTable := FContrato.DataTable;
|
|||
|
|
|
|||
|
|
frViewIncidenciasCli.DADataSource.DataTable := dsDataTable.DataTable;
|
|||
|
|
frViewTotales1.DADataSource.DataTable := FContrato.DataTable;
|
|||
|
|
|
|||
|
|
FTiposIVA := FTiposIVAController.BuscarTodos;
|
|||
|
|
frViewTotales1.dsTiposIVA.DataTable := FTiposIVA.DataTable;
|
|||
|
|
FTiposIVA.DataTable.Active := True;
|
|||
|
|
|
|||
|
|
if Assigned(FViewContrato) then
|
|||
|
|
begin
|
|||
|
|
ViewContrato.ViewClienteContrato.OnClienteChanged := NIL;
|
|||
|
|
try
|
|||
|
|
FViewContrato.Contrato := FContrato;
|
|||
|
|
frViewDetallesContratoCliente1.Detalles := FContrato.Detalles;
|
|||
|
|
frViewDetallesContratoCliente1.Contrato := FContrato; //Para poder sacar los descuento del articulos segun el cliente seleccionado
|
|||
|
|
|
|||
|
|
//GESTION_DOCUMENTOS
|
|||
|
|
frViewDocumentosContratoCliente1.Contrato := FContrato;
|
|||
|
|
|
|||
|
|
finally
|
|||
|
|
ViewContrato.ViewClienteContrato.OnClienteChanged := OnClienteChanged;
|
|||
|
|
end;
|
|||
|
|
end;
|
|||
|
|
end;
|
|||
|
|
end;
|
|||
|
|
|
|||
|
|
procedure TfEditorContratoCliente.SetViewContrato(const Value: IViewContratoCliente);
|
|||
|
|
begin
|
|||
|
|
FViewContrato := Value;
|
|||
|
|
|
|||
|
|
if Assigned(FViewContrato) then
|
|||
|
|
begin
|
|||
|
|
FViewClienteContrato := FViewContrato.ViewClienteContrato;
|
|||
|
|
|
|||
|
|
if Assigned(Contrato) then
|
|||
|
|
FViewContrato.Contrato := Contrato;
|
|||
|
|
end;
|
|||
|
|
end;
|
|||
|
|
|
|||
|
|
end.
|