342 lines
11 KiB
ObjectPascal
342 lines
11 KiB
ObjectPascal
|
|
unit uEditorPresupuestoCliente;
|
|||
|
|
|
|||
|
|
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,
|
|||
|
|
uPresupuestosClienteController,
|
|||
|
|
uViewDetallesBase,
|
|||
|
|
dxLayoutLookAndFeels, JvExComCtrls, JvStatusBar, uViewTotales,
|
|||
|
|
uIEditorPresupuestoCliente, uBizPresupuestosCliente, uViewPresupuestoCliente,
|
|||
|
|
uViewDetallesDTO, uViewDetallesArticulos, uViewDetallesPresupuestoCliente,
|
|||
|
|
uDAInterfaces;
|
|||
|
|
|
|||
|
|
type
|
|||
|
|
TfEditorPresupuestoCliente = class(TfEditorDBItem, IEditorPresupuestoCliente)
|
|||
|
|
pagContenido: TTabSheet;
|
|||
|
|
pagInicidencias: TTabSheet;
|
|||
|
|
frViewIncidenciasCli: TfrViewIncidencias;
|
|||
|
|
dxLayoutLookAndFeelList1: TdxLayoutLookAndFeelList;
|
|||
|
|
dxLayoutOfficeLookAndFeel1: TdxLayoutOfficeLookAndFeel;
|
|||
|
|
frViewTotales1: TfrViewTotales;
|
|||
|
|
frViewDetallesPresupuestoCliente1: TfrViewDetallesPresupuestoCliente;
|
|||
|
|
|
|||
|
|
procedure FormShow(Sender: TObject); override;
|
|||
|
|
procedure CustomEditorClose(Sender: TObject; var Action: TCloseAction);
|
|||
|
|
procedure pgPaginasChanging(Sender: TObject; var AllowChange: Boolean);
|
|||
|
|
procedure frViewTotales1ePortePropertiesValidate(Sender: TObject;
|
|||
|
|
var DisplayValue: Variant; var ErrorText: TCaption; var Error: Boolean);
|
|||
|
|
private
|
|||
|
|
procedure RecalcularPortePorUnidad;
|
|||
|
|
|
|||
|
|
protected
|
|||
|
|
FPedido: IBizPresupuestoCliente;
|
|||
|
|
FViewPedido: IViewPresupuestoCliente;
|
|||
|
|
FController : IPresupuestosClienteController;
|
|||
|
|
|
|||
|
|
function GetController : IPresupuestosClienteController;
|
|||
|
|
procedure SetController (const Value : IPresupuestosClienteController); virtual;
|
|||
|
|
|
|||
|
|
function GetPedido: IBizPresupuestoCliente;
|
|||
|
|
procedure SetPedido(const Value: IBizPresupuestoCliente); virtual;
|
|||
|
|
|
|||
|
|
function GetViewPedido: IViewPresupuestoCliente;
|
|||
|
|
procedure SetViewPedido(const Value: IViewPresupuestoCliente);
|
|||
|
|
|
|||
|
|
procedure PrevisualizarInterno; override;
|
|||
|
|
procedure ImprimirInterno; override;
|
|||
|
|
procedure GuardarInterno; override;
|
|||
|
|
procedure EliminarInterno; override;
|
|||
|
|
|
|||
|
|
property ViewPedido: IViewPresupuestoCliente read GetViewPedido write SetViewPedido;
|
|||
|
|
|
|||
|
|
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;
|
|||
|
|
public
|
|||
|
|
property Controller : IPresupuestosClienteController read GetController write SetController;
|
|||
|
|
property Pedido: IBizPresupuestoCliente read GetPedido write SetPedido;
|
|||
|
|
constructor Create(AOwner: TComponent); override;
|
|||
|
|
destructor Destroy; override;
|
|||
|
|
end;
|
|||
|
|
|
|||
|
|
implementation
|
|||
|
|
|
|||
|
|
uses
|
|||
|
|
uViewDatosYSeleccionCliente, uDataModuleUsuarios, uClientesController,
|
|||
|
|
uBizDireccionesContacto, uDialogUtils;
|
|||
|
|
|
|||
|
|
{$R *.dfm}
|
|||
|
|
|
|||
|
|
{ TfEditorPresupuestoCliente }
|
|||
|
|
|
|||
|
|
{
|
|||
|
|
**************************** TfEditorPresupuestoCliente ****************************
|
|||
|
|
}
|
|||
|
|
procedure TfEditorPresupuestoCliente.AsignarVista;
|
|||
|
|
var
|
|||
|
|
AViewPresupuestoCliente: TfrViewPresupuestoCliente;
|
|||
|
|
|
|||
|
|
begin
|
|||
|
|
AViewPresupuestoCliente := TfrViewPresupuestoCliente.create(Self);
|
|||
|
|
with AViewPresupuestoCliente do
|
|||
|
|
begin
|
|||
|
|
Parent := pagGeneral;
|
|||
|
|
Align := alClient;
|
|||
|
|
dxLayoutControl1.LookAndFeel := dxLayoutOfficeLookAndFeel1;
|
|||
|
|
end;
|
|||
|
|
ViewPedido := AViewPresupuestoCliente;
|
|||
|
|
end;
|
|||
|
|
|
|||
|
|
constructor TfEditorPresupuestoCliente.Create(AOwner: TComponent);
|
|||
|
|
begin
|
|||
|
|
inherited;
|
|||
|
|
pgPaginas.ActivePageIndex := 0;
|
|||
|
|
|
|||
|
|
AsignarVista;
|
|||
|
|
end;
|
|||
|
|
|
|||
|
|
procedure TfEditorPresupuestoCliente.CustomEditorClose(Sender: TObject;
|
|||
|
|
var Action: TCloseAction);
|
|||
|
|
begin
|
|||
|
|
inherited;
|
|||
|
|
FViewPedido := NIL;
|
|||
|
|
FPedido := NIL;
|
|||
|
|
end;
|
|||
|
|
|
|||
|
|
destructor TfEditorPresupuestoCliente.Destroy;
|
|||
|
|
begin
|
|||
|
|
// Utilizar mejor OnClose;
|
|||
|
|
inherited;
|
|||
|
|
end;
|
|||
|
|
|
|||
|
|
procedure TfEditorPresupuestoCliente.EliminarInterno;
|
|||
|
|
begin
|
|||
|
|
if (ShowConfirmMessage('<27>Desea borrar este pedido de cliente?', '') = IDYES) then
|
|||
|
|
begin
|
|||
|
|
FController.Eliminar(FPedido);
|
|||
|
|
inherited
|
|||
|
|
end
|
|||
|
|
end;
|
|||
|
|
|
|||
|
|
procedure TfEditorPresupuestoCliente.FormShow(Sender: TObject);
|
|||
|
|
begin
|
|||
|
|
inherited;
|
|||
|
|
|
|||
|
|
if not Assigned(FViewPedido) then
|
|||
|
|
raise Exception.Create('No hay ninguna vista asignada');
|
|||
|
|
|
|||
|
|
if not Assigned(Pedido) then
|
|||
|
|
raise Exception.Create('No hay ning<6E>n pedido asignado');
|
|||
|
|
|
|||
|
|
Pedido.DataTable.Active := True;
|
|||
|
|
pgPaginas.ActivePage := pagGeneral;
|
|||
|
|
end;
|
|||
|
|
|
|||
|
|
procedure TfEditorPresupuestoCliente.frViewTotales1ePortePropertiesValidate(
|
|||
|
|
Sender: TObject; var DisplayValue: Variant; var ErrorText: TCaption;
|
|||
|
|
var Error: Boolean);
|
|||
|
|
begin
|
|||
|
|
inherited;
|
|||
|
|
if not VarIsNull(DisplayValue) then
|
|||
|
|
FPedido.IMPORTE_PORTE := DisplayValue
|
|||
|
|
else
|
|||
|
|
FPedido.IMPORTE_PORTE := 0;
|
|||
|
|
|
|||
|
|
RecalcularPortePorUnidad;
|
|||
|
|
end;
|
|||
|
|
|
|||
|
|
function TfEditorPresupuestoCliente.GetController: IPresupuestosClienteController;
|
|||
|
|
begin
|
|||
|
|
Result := FController;
|
|||
|
|
end;
|
|||
|
|
|
|||
|
|
function TfEditorPresupuestoCliente.GetPedido: IBizPresupuestoCliente;
|
|||
|
|
begin
|
|||
|
|
Result := FPedido;
|
|||
|
|
end;
|
|||
|
|
|
|||
|
|
function TfEditorPresupuestoCliente.GetViewPedido: IViewPresupuestoCliente;
|
|||
|
|
begin
|
|||
|
|
Result := FViewPedido;
|
|||
|
|
end;
|
|||
|
|
|
|||
|
|
procedure TfEditorPresupuestoCliente.GuardarInterno;
|
|||
|
|
var
|
|||
|
|
bEsNuevo : Boolean;
|
|||
|
|
begin
|
|||
|
|
inherited;
|
|||
|
|
bEsNuevo := False;
|
|||
|
|
|
|||
|
|
ShowHourglassCursor;
|
|||
|
|
// frViewDetallesPresupuestoCliente1.SaveGridStatus;
|
|||
|
|
frViewDetallesPresupuestoCliente1.BeginUpdate;
|
|||
|
|
try
|
|||
|
|
bEsNuevo := FPedido.EsNuevo;
|
|||
|
|
FController.Guardar(FPedido);
|
|||
|
|
finally
|
|||
|
|
frViewDetallesPresupuestoCliente1.EndUpdate;
|
|||
|
|
// frViewDetallesPresupuestoCliente1.RestoreGridStatus;
|
|||
|
|
HideHourglassCursor;
|
|||
|
|
end;
|
|||
|
|
if bEsNuevo then
|
|||
|
|
ShowInfoMessage('El pedido se ha dado de alta con el c<>digo ' + FPedido.REFERENCIA);
|
|||
|
|
|
|||
|
|
Modified := False;
|
|||
|
|
end;
|
|||
|
|
|
|||
|
|
procedure TfEditorPresupuestoCliente.ImprimirInterno;
|
|||
|
|
begin
|
|||
|
|
inherited;
|
|||
|
|
if not Modified then
|
|||
|
|
FController.Print(FPedido);
|
|||
|
|
end;
|
|||
|
|
|
|||
|
|
procedure TfEditorPresupuestoCliente.OnClienteChanged(Sender: TObject);
|
|||
|
|
var
|
|||
|
|
AClientesController : IClientesController;
|
|||
|
|
ADireccion : IBizDireccionesContacto;
|
|||
|
|
begin
|
|||
|
|
if Assigned(FPedido) then
|
|||
|
|
begin
|
|||
|
|
FPedido.Cliente := ViewPedido.ViewClientePedido.Cliente;
|
|||
|
|
|
|||
|
|
AClientesController := TClientesController.Create;
|
|||
|
|
try
|
|||
|
|
if not AClientesController.TieneDatosBancarios(FPedido.Cliente) then
|
|||
|
|
MessageBox(0, 'Este cliente no tiene datos bancarios en su ficha', 'Atenci<63>n', MB_ICONWARNING or MB_OK);
|
|||
|
|
|
|||
|
|
case FPedido.Cliente.Direcciones.RecordCount of
|
|||
|
|
0 : begin
|
|||
|
|
FController.QuitarDireccionEnvio(FPedido);
|
|||
|
|
MessageBox(0, '<27>Atenci<63>n! Este cliente no tiene ' + #10#13 + 'ninguna direcci<63>n de env<6E>o en su ficha', 'Atenci<63>n', MB_ICONWARNING or MB_OK);
|
|||
|
|
FPedido.Edit;
|
|||
|
|
FPedido.IMPORTE_PORTE := 0;
|
|||
|
|
end;
|
|||
|
|
1 : begin
|
|||
|
|
FController.CopiarDireccionEnvio(FPedido.Cliente.Direcciones, FPedido);
|
|||
|
|
FPedido.Edit;
|
|||
|
|
FPedido.IMPORTE_PORTE := FPedido.Cliente.Direcciones.PORTE;
|
|||
|
|
end
|
|||
|
|
else begin
|
|||
|
|
ADireccion := AClientesController.ElegirDireccionEntrega(FPedido.Cliente.Direcciones, '');
|
|||
|
|
try
|
|||
|
|
if Assigned(ADireccion) then
|
|||
|
|
begin
|
|||
|
|
FController.CopiarDireccionEnvio(ADireccion, FPedido);
|
|||
|
|
FPedido.Edit;
|
|||
|
|
FPedido.IMPORTE_PORTE := ADireccion.PORTE;
|
|||
|
|
end;
|
|||
|
|
finally
|
|||
|
|
ADireccion := NIL;
|
|||
|
|
end;
|
|||
|
|
end;
|
|||
|
|
end;
|
|||
|
|
|
|||
|
|
// Si el pedido tiene detalles hay que mirar si los descuentos y otros campos
|
|||
|
|
// para los art<72>culos hay que cambiarlos.
|
|||
|
|
if (FPedido.Detalles.RecordCount > 0) then
|
|||
|
|
FController.DetallesController.ActualizarDetalles(FPedido.Detalles, FPedido.Cliente);
|
|||
|
|
|
|||
|
|
finally
|
|||
|
|
AClientesController := NIL;
|
|||
|
|
end;
|
|||
|
|
end;
|
|||
|
|
end;
|
|||
|
|
|
|||
|
|
procedure TfEditorPresupuestoCliente.pgPaginasChanging(Sender: TObject; var AllowChange: Boolean);
|
|||
|
|
begin
|
|||
|
|
inherited;
|
|||
|
|
if (not Assigned(FPedido)) or (FPedido.ID_CLIENTE = 0) then
|
|||
|
|
begin
|
|||
|
|
ShowWarningMessage('Antes de introducir conceptos debe elegir un cliente para este pedido');
|
|||
|
|
AllowChange := False;
|
|||
|
|
end;
|
|||
|
|
end;
|
|||
|
|
|
|||
|
|
procedure TfEditorPresupuestoCliente.PonerTitulos(const ATitulo: string);
|
|||
|
|
var
|
|||
|
|
FTitulo : String;
|
|||
|
|
begin
|
|||
|
|
FTitulo := ATitulo;
|
|||
|
|
if (FTitulo = '') and Assigned(FPedido) then
|
|||
|
|
begin
|
|||
|
|
if FPedido.EsNuevo then
|
|||
|
|
FTitulo := 'Nuevo pedido de cliente'
|
|||
|
|
else
|
|||
|
|
FTitulo := 'Pedido de cliente' + ' - ' + FPedido.Cliente.Nombre + ' - ' + FPedido.SITUACION;
|
|||
|
|
end;
|
|||
|
|
|
|||
|
|
inherited PonerTitulos(FTitulo);
|
|||
|
|
|
|||
|
|
// Self.Caption := FTitulo + ' (' + dmUsuarios.EmpresaActual.NOMBRE + ')';
|
|||
|
|
end;
|
|||
|
|
|
|||
|
|
procedure TfEditorPresupuestoCliente.PrevisualizarInterno;
|
|||
|
|
begin
|
|||
|
|
inherited;
|
|||
|
|
if not Modified then
|
|||
|
|
FController.Preview(FPedido);
|
|||
|
|
end;
|
|||
|
|
|
|||
|
|
procedure TfEditorPresupuestoCliente.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(FPedido.IMPORTE_PORTE, FPedido.Detalles)
|
|||
|
|
end;
|
|||
|
|
|
|||
|
|
procedure TfEditorPresupuestoCliente.SetController(const Value: IPresupuestosClienteController);
|
|||
|
|
begin
|
|||
|
|
FController := Value;
|
|||
|
|
|
|||
|
|
if Assigned(FController) then
|
|||
|
|
begin
|
|||
|
|
ViewPedido.ViewClientePedido.Controller := Controller.ClienteController;
|
|||
|
|
frViewDetallesPresupuestoCliente1.Controller := Controller.DetallesController;
|
|||
|
|
end;
|
|||
|
|
end;
|
|||
|
|
|
|||
|
|
procedure TfEditorPresupuestoCliente.SetPedido(const Value: IBizPresupuestoCliente);
|
|||
|
|
begin
|
|||
|
|
FPedido := Value;
|
|||
|
|
|
|||
|
|
if Assigned(FPedido) then
|
|||
|
|
begin
|
|||
|
|
dsDataTable.DataTable := FPedido.DataTable;
|
|||
|
|
frViewIncidenciasCli.DADataSource.DataTable := dsDataTable.DataTable;
|
|||
|
|
frViewTotales1.DADataSource.DataTable := dsDataTable.DataTable;
|
|||
|
|
if Assigned(FViewPedido) then
|
|||
|
|
begin
|
|||
|
|
FViewPedido.Pedido := FPedido;
|
|||
|
|
ViewPedido.ViewClientePedido.Cliente := FPedido.Cliente;
|
|||
|
|
ViewPedido.ViewClientePedido.OnClienteChanged := OnClienteChanged;
|
|||
|
|
frViewDetallesPresupuestoCliente1.Detalles := FPedido.Detalles;
|
|||
|
|
frViewDetallesPresupuestoCliente1.Pedido := FPedido; //Para poder sacar los descuento del articulos segun el cliente seleccionado
|
|||
|
|
end;
|
|||
|
|
end;
|
|||
|
|
end;
|
|||
|
|
|
|||
|
|
procedure TfEditorPresupuestoCliente.SetViewPedido(const Value: IViewPresupuestoCliente);
|
|||
|
|
begin
|
|||
|
|
FViewPedido := Value;
|
|||
|
|
|
|||
|
|
if Assigned(FViewPedido) and Assigned(Pedido) then
|
|||
|
|
FViewPedido.Pedido := Pedido;
|
|||
|
|
end;
|
|||
|
|
|
|||
|
|
end.
|