git-svn-id: https://192.168.0.254/svn/Proyectos.Acana_FactuGES/trunk@4 3f40d355-893c-4141-8e64-b1d9be72e7e7
1560 lines
45 KiB
ObjectPascal
1560 lines
45 KiB
ObjectPascal
{
|
|
===============================================================================
|
|
Copyright (©) 2002. Rodax Software.
|
|
===============================================================================
|
|
Los contenidos de este fichero son propiedad de Rodax Software titular del
|
|
copyright. Este fichero sólo podrá ser copiado, distribuido y utilizado,
|
|
en su totalidad o en parte, con el permiso escrito de Rodax Software, o de
|
|
acuerdo con los términos y condiciones establecidas en el acuerdo/contrato
|
|
bajo el que se suministra.
|
|
-----------------------------------------------------------------------------
|
|
Web: www.rodax-software.com
|
|
===============================================================================
|
|
Fecha primera versión: 26-12-2002
|
|
Versión actual: 1.0.3
|
|
Fecha versión actual: 19-07-2004
|
|
===============================================================================
|
|
Modificaciones:
|
|
|
|
Fecha Comentarios
|
|
---------------------------------------------------------------------------
|
|
25-03-2003 Añadido el recargo de equivalencia.
|
|
10-05-2003 Error con el código de factura al escribirlo manualmente.
|
|
25-08-2003 Al dar de alta una factura, el cliente debe estar también
|
|
dado de alta.
|
|
19-07-2004 p13. En los menus contextuales deben aparecer las opciones
|
|
de cortar, copiar y pegar.
|
|
|
|
===============================================================================
|
|
}
|
|
|
|
unit FacturaProforma;
|
|
|
|
interface
|
|
|
|
uses
|
|
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
|
|
Grids, DBGrids, RdxBotones, RdxTitulos, StdCtrls,
|
|
RdxMemo, RdxCampos, ExtCtrls, RdxComboBox, RdxPaneles, RdxBarras, ComCtrls,
|
|
RdxRichEdit, RXDBCtrl, RdxFrame, RdxPageControl, Db,
|
|
RdxRadioButton, RxMemDS, IBCustomDataSet,
|
|
cxStyles, cxCustomData, cxGraphics,
|
|
cxFilter, cxData, cxEdit, cxDBData, cxGridLevel, cxClasses, cxControls,
|
|
cxGridCustomView, cxGridCustomTableView, cxGridTableView,
|
|
cxGridDBTableView, cxGrid, Configuracion, cxContainer, cxTextEdit,
|
|
cxMaskEdit, cxDropDownEdit, cxCalendar, cxDBEdit,
|
|
cxButtonEdit, cxMemo, cxSpinEdit, AdvPanel, ActnList, Menus,
|
|
am2000menuitem, am2000popupmenu, am2000, RdxCheckBox, cxCheckBox, cxCalc,
|
|
cxCurrencyEdit, RdxFrameFacturasProforma,
|
|
|
|
RdxEmpresaActiva, am2000utils, cxDataStorage;
|
|
|
|
type
|
|
TfrFacturaProforma = class(TRdxFrameFacturasProforma)
|
|
brSalir: TRdxBarraInferior;
|
|
bSalir: TRdxBoton;
|
|
brGuardar: TRdxBarraInferior;
|
|
bGuardar: TRdxBoton;
|
|
bCancelar: TRdxBoton;
|
|
Titulo: TRdxPanelTituloOperacion;
|
|
dsFactura: TDataSource;
|
|
dsDetallesFacturas: TDataSource;
|
|
pnlCuerpo: TPanel;
|
|
pnlDatosFactura: TAdvPanel;
|
|
eCodigo: TLabel;
|
|
eFormaPago: TLabel;
|
|
Label1: TLabel;
|
|
Codigo: TcxDBButtonEdit;
|
|
FechaFactura: TcxDBDateEdit;
|
|
pnlGrid: TAdvPanel;
|
|
Paginas: TRdxPagesControl;
|
|
pagCliente: TTabSheet;
|
|
pagContenido: TTabSheet;
|
|
pnlGridArticulos: TPanel;
|
|
pnlBarraGrid: TPanel;
|
|
bAnadirCon: TRdxBoton;
|
|
bEliminar: TRdxBoton;
|
|
bEliminarTodo: TRdxBoton;
|
|
gridDetalles: TcxGrid;
|
|
VistaDetalles: TcxGridDBTableView;
|
|
gridDetallesLevel1: TcxGridLevel;
|
|
pagObservaciones: TTabSheet;
|
|
RdxPanel4: TPanel;
|
|
Label3: TLabel;
|
|
RdxPanel5: TPanel;
|
|
Observaciones: TcxDBMemo;
|
|
Label2: TLabel;
|
|
CodCliente: TcxDBButtonEdit;
|
|
eNIFCIF: TLabel;
|
|
NIFCIF: TcxDBTextEdit;
|
|
eNombre: TLabel;
|
|
Nombre: TcxDBTextEdit;
|
|
eDireccion: TLabel;
|
|
Calle: TcxDBTextEdit;
|
|
eProvincia: TLabel;
|
|
Provincia: TcxDBButtonEdit;
|
|
ePoblacion: TLabel;
|
|
Poblacion: TcxDBButtonEdit;
|
|
eTelefono1: TLabel;
|
|
Telefono1: TcxDBTextEdit;
|
|
eTelefono2: TLabel;
|
|
Telefono2: TcxDBTextEdit;
|
|
eNumero: TLabel;
|
|
Numero: TcxDBTextEdit;
|
|
ePiso: TLabel;
|
|
Piso: TcxDBTextEdit;
|
|
eCodigoPostal: TLabel;
|
|
CodigoPostal: TcxDBTextEdit;
|
|
eFax: TLabel;
|
|
Fax: TcxDBTextEdit;
|
|
eMovil2: TLabel;
|
|
Movil2: TcxDBTextEdit;
|
|
eMovil1: TLabel;
|
|
Movil1: TcxDBTextEdit;
|
|
ePersona: TLabel;
|
|
PersonaContacto: TcxDBTextEdit;
|
|
cbxFormaPago: TcxDBComboBox;
|
|
ActionList1: TActionList;
|
|
actAnadirConcepto: TAction;
|
|
actEliminar: TAction;
|
|
actEliminarTodo: TAction;
|
|
pnlImportes: TAdvPanel;
|
|
Label7: TLabel;
|
|
Label8: TLabel;
|
|
Panel1: TPanel;
|
|
Label5: TLabel;
|
|
Label9: TLabel;
|
|
BaseImponible: TcxDBTextEdit;
|
|
ImporteTotal: TcxDBTextEdit;
|
|
ImporteDescuento: TcxDBTextEdit;
|
|
ImporteIVA: TcxDBTextEdit;
|
|
RdxPanel1: TRdxPanel;
|
|
Label10: TLabel;
|
|
Label11: TLabel;
|
|
Shape2: TShape;
|
|
Panel2: TPanel;
|
|
cbRecargoEquivalencia: TcxCheckBox;
|
|
Descuento: TcxDBTextEdit;
|
|
IVA: TcxDBTextEdit;
|
|
RecargoEquivalencia: TcxDBTextEdit;
|
|
procedure bCancelarClick(Sender: TObject);
|
|
procedure bSalirClick(Sender: TObject);
|
|
procedure bGuardarClick(Sender: TObject);
|
|
procedure CodigoExit(Sender: TObject);
|
|
procedure CodClienteExit(Sender: TObject);
|
|
procedure CodigoPropertiesButtonClick(Sender: TObject;
|
|
AButtonIndex: Integer);
|
|
procedure CodClientePropertiesButtonClick(Sender: TObject;
|
|
AButtonIndex: Integer);
|
|
procedure ProvinciaPropertiesButtonClick(Sender: TObject;
|
|
AButtonIndex: Integer);
|
|
procedure PoblacionPropertiesButtonClick(Sender: TObject;
|
|
AButtonIndex: Integer);
|
|
procedure actAnadirConceptoExecute(Sender: TObject);
|
|
procedure actEliminarExecute(Sender: TObject);
|
|
procedure actEliminarTodoExecute(Sender: TObject);
|
|
procedure cbRecargoEquivalenciaPropertiesChange(Sender: TObject);
|
|
procedure actEliminarUpdate(Sender: TObject);
|
|
procedure actEliminarTodoUpdate(Sender: TObject);
|
|
private
|
|
FCodigoProvincia : Variant;
|
|
FCodigoPoblacion : Variant;
|
|
FCodigoCliente : Variant;
|
|
FCodigoArticulo : Variant;
|
|
FTablaDetallesMem : TRxMemoryData;
|
|
procedure CalcularTotalDetalle;
|
|
procedure CalcularTotalFactura;
|
|
procedure ActivarEventosCampos;
|
|
procedure DesactivarEventosCampos;
|
|
procedure CodCliSetText(Sender: TField; const Text: String);
|
|
procedure IVASetText(Sender: TField; const Text: String);
|
|
procedure DtoSetText(Sender: TField; const Text: String);
|
|
procedure RESetText(Sender: TField; const Text: String);
|
|
procedure BorrarDetalles;
|
|
procedure SalvarDetalles;
|
|
procedure CargarDetalles;
|
|
procedure BorrarDetallesIB;
|
|
procedure ReordenarDetallesMem;
|
|
procedure IntercambiarDetallesMem(PosCon1, PosCon2 : Integer);
|
|
procedure DetalleAfterDelete (DataSet: TDataSet);
|
|
procedure GridBotonCodigoArticuloClick(Sender: TObject; AButtonIndex: Integer);
|
|
procedure CodigoArticuloDetalleSetText(Sender: TField; const Text: String);
|
|
procedure CantidadDetalleSetText(Sender: TField; const Text: String);
|
|
procedure PrecioDetalleSetText(Sender: TField; const Text: String);
|
|
procedure ProvinciaSetText(Sender: TField; const Text: String);
|
|
procedure DetallesAfterInsert(DataSet: TDataSet);
|
|
function GetCodigoCliente: Variant;
|
|
protected
|
|
procedure ActivarModoAnadir; override;
|
|
procedure ActivarModoModificar; override;
|
|
procedure ActivarModoConsultar; override;
|
|
procedure ActivarModoEliminar; override;
|
|
function AnadirDatos : Boolean; override;
|
|
function ModificarDatos : Boolean; override;
|
|
function EliminarDatos : Boolean; override;
|
|
function CancelarAnadir : Boolean; override;
|
|
function CancelarModificar : Boolean; override;
|
|
function CancelarEliminar : Boolean; override;
|
|
function ComprobarDatos : Boolean; override;
|
|
procedure VerModal; override;
|
|
procedure SetCodigoProvincia (Value : Variant); virtual;
|
|
procedure SetCodigoPoblacion (Value : Variant); virtual;
|
|
procedure SetCodigoCliente (Value : Variant);
|
|
procedure SetCodigoArticulo (Value : Variant);
|
|
procedure FreeContenido; override;
|
|
procedure BuscarFactura; override;
|
|
public
|
|
property CodigoProvincia : Variant read FCodigoProvincia write SetCodigoProvincia;
|
|
property CodigoPoblacion : Variant read FCodigoPoblacion write SetCodigoPoblacion;
|
|
property CodigoCliente : Variant read GetCodigoCliente write SetCodigoCliente;
|
|
property CodigoArticulo : Variant read FCodigoArticulo write SetCodigoArticulo;
|
|
constructor Create (AOwner : TComponent); override;
|
|
destructor Destroy; override;
|
|
published
|
|
property TablaFacturas;
|
|
property TablaDetallesFacturas;
|
|
property TablaDetallesMem : TRxMemoryData read FTablaDetallesMem write FTablaDetallesMem;
|
|
end;
|
|
|
|
var
|
|
frFacturaProforma: TfrFacturaProforma;
|
|
|
|
implementation
|
|
|
|
{$R *.DFM}
|
|
|
|
uses
|
|
Variants, Entidades, FacturasClientes, BaseDatos, IBDatabase,
|
|
Mensajes, Clientes, RdxFrameProvincias, RdxFramePoblaciones, TablaTrimestres,
|
|
TablaProvincias, Provincias, Poblaciones, TablaClientes, RdxFrameClientes,
|
|
IB, Articulos, RdxFrameArticulos, TablaArticulos, Constantes,
|
|
StrFunc, TablaPoblaciones, TablaFormasPago, NumFunc,
|
|
IBSQL, Excepciones, IBErrorCodes, Literales, ElegirDireccionCliente,
|
|
TablaFacturasProforma, TablaEmpresas;
|
|
|
|
procedure TfrFacturaProforma.bCancelarClick(Sender: TObject);
|
|
begin
|
|
if (TratarCambios = IDOK) then
|
|
CloseFrame;
|
|
end;
|
|
|
|
procedure TfrFacturaProforma.bSalirClick(Sender: TObject);
|
|
begin
|
|
try
|
|
Rollback;
|
|
CloseFrame;
|
|
except
|
|
on E : EIBError do
|
|
TratarExcepcion(E);
|
|
on E : Exception do
|
|
TratarExcepcion(E);
|
|
end;
|
|
end;
|
|
|
|
procedure TfrFacturaProforma.bGuardarClick(Sender: TObject);
|
|
begin
|
|
if (RealizarOperacion) then
|
|
CloseFrame;
|
|
end;
|
|
|
|
procedure TfrFacturaProforma.ActivarEventosCampos;
|
|
begin
|
|
cbRecargoEquivalencia.Properties.OnChange := cbRecargoEquivalenciaPropertiesChange;
|
|
|
|
with TablaFacturas do
|
|
begin
|
|
FieldByName('CODIGOCLIENTE').OnSetText := CodCliSetText;
|
|
FieldByName('IVA').OnSetText := IVASetText;
|
|
FieldByName('DESCUENTO').OnSetText := DtoSetText;
|
|
FieldByName('RE').OnSetText := RESetText;
|
|
end;
|
|
|
|
with TablaDetallesMem do
|
|
begin
|
|
FieldByName('CODIGOARTICULO').OnSetText := CodigoArticuloDetalleSetText;
|
|
FieldByName('CANTIDAD').OnSetText := CantidadDetalleSetText;
|
|
FieldByName('IMPORTEUNIDAD').OnSetText := PrecioDetalleSetText;
|
|
AfterDelete := DetalleAfterDelete;
|
|
AfterInsert := DetallesAfterInsert;
|
|
end;
|
|
|
|
with VistaDetalles do
|
|
begin
|
|
TcxButtonEditProperties(GetColumnByFieldName('CODIGOARTICULO').Properties).OnButtonClick := GridBotonCodigoArticuloClick;
|
|
end;
|
|
end;
|
|
|
|
procedure TfrFacturaProforma.ActivarModoAnadir;
|
|
var
|
|
CodNuevo : Variant;
|
|
begin
|
|
dsFactura.AutoEdit := True;
|
|
dsDetallesFacturas.AutoEdit := True;
|
|
pnlBarraGrid.Visible := True;
|
|
|
|
Codigo.Properties.Buttons[0].Visible := False;
|
|
Codigo.Properties.ReadOnly := False;
|
|
CodCliente.Properties.Buttons[0].Visible := True;
|
|
Poblacion.Properties.Buttons[0].Visible := True;
|
|
Provincia.Properties.Buttons[0].Visible := True;
|
|
cbRecargoEquivalencia.Checked := False;
|
|
RecargoEquivalencia.Enabled := False;
|
|
|
|
try
|
|
CodNuevo := dmTablaFacturasProforma.DarNuevoCodigo;
|
|
|
|
with TablaFacturas do
|
|
begin
|
|
Close;
|
|
Prepare;
|
|
Open;
|
|
FieldByName('PROVINCIA').OnSetText := ProvinciaSetText;
|
|
Insert;
|
|
Codigo.DataBinding.Field.AsString := CodNuevo;
|
|
FieldByName('CODIGOEMPRESA').AsInteger := EmpresaActiva.Codigo;
|
|
FieldByName('FECHAALTA').AsDateTime := dmBaseDatos.DarFecha;
|
|
FieldByName('USUARIO').AsString := dmBaseDatos.Usuario;
|
|
FieldByName('IVA').AsString := EmpresaActiva.IvaDefecto;
|
|
FechaFactura.DataBinding.Field.AsDateTime := dmBaseDatos.DarFecha;
|
|
end;
|
|
|
|
with TablaDetallesFacturas do
|
|
begin
|
|
Close;
|
|
ParamByName('CODIGOEMPRESA').AsInteger := EmpresaActiva.Codigo;
|
|
ParamByName('CODIGOFACTURA').AsString := CodNuevo;
|
|
Prepare;
|
|
Open;
|
|
end;
|
|
|
|
with TablaDetallesMem do
|
|
begin
|
|
Close;
|
|
Open;
|
|
if not IsEmpty then
|
|
Edit;
|
|
end;
|
|
|
|
dmTablaFacturasProforma.InicializarTablaFacturas(@TablaFacturas);
|
|
dmTablaFacturasProforma.InicializarTablaDetalles(@TablaDetallesMem);
|
|
cbRecargoEquivalencia.Properties.ReadOnly := False;
|
|
ActivarEdicionGridDetalles(gridDetalles);
|
|
ActivarEventosCampos;
|
|
Visible := True;
|
|
FechaFactura.SetFocus;
|
|
except
|
|
on E : EIBError do
|
|
TratarExcepcion(E);
|
|
on E : Exception do
|
|
TratarExcepcion(E);
|
|
end;
|
|
end;
|
|
|
|
procedure TfrFacturaProforma.ActivarModoConsultar;
|
|
begin
|
|
dsFactura.AutoEdit := False;
|
|
dsDetallesFacturas.AutoEdit := False;
|
|
pnlBarraGrid.Visible := False;
|
|
|
|
Codigo.Properties.Buttons[0].Visible := True;
|
|
CodCliente.Properties.Buttons[0].Visible := False;
|
|
Poblacion.Properties.Buttons[0].Visible := False;
|
|
Provincia.Properties.Buttons[0].Visible := False;
|
|
|
|
try
|
|
with TablaFacturas do
|
|
begin
|
|
Prepare;
|
|
Open;
|
|
|
|
if RecordCount = 0 then
|
|
begin
|
|
VerMensajeFmt(msgCliNoExisteFac, [CodigoFactura]);
|
|
CloseFrame;
|
|
Exit;
|
|
end;
|
|
Cancel;
|
|
end;
|
|
|
|
with TablaDetallesFacturas do
|
|
begin
|
|
Close;
|
|
Params.ByName('CODIGOFACTURA').AsString := CodigoFactura;
|
|
Prepare;
|
|
Open;
|
|
Cancel;
|
|
end;
|
|
|
|
with TablaDetallesMem do
|
|
begin
|
|
Close;
|
|
Open;
|
|
Cancel;
|
|
CargarDetalles;
|
|
end;
|
|
|
|
dmTablaFacturasProforma.InicializarTablaFacturas(@TablaFacturas);
|
|
dmTablaFacturasProforma.InicializarTablaDetalles(@TablaDetallesMem);
|
|
DesactivarEventosCampos;
|
|
DesactivarEdicionGridDetalles(gridDetalles);
|
|
cbRecargoEquivalencia.Checked := TablaFacturas.FieldByName('RE').AsFloat > 0;
|
|
RecargoEquivalencia.Enabled := TablaFacturas.FieldByName('RE').AsFloat > 0;
|
|
cbRecargoEquivalencia.Properties.ReadOnly := True;
|
|
Visible := True;
|
|
FechaFactura.SetFocus;
|
|
except
|
|
on E : EIBError do
|
|
TratarExcepcion(E);
|
|
on E : Exception do
|
|
TratarExcepcion(E);
|
|
end;
|
|
end;
|
|
|
|
procedure TfrFacturaProforma.ActivarModoEliminar;
|
|
begin
|
|
dsFactura.AutoEdit := False;
|
|
dsDetallesFacturas.AutoEdit := False;
|
|
pnlBarraGrid.Visible := False;
|
|
|
|
Codigo.Properties.Buttons[0].Visible := True;
|
|
CodCliente.Properties.Buttons[0].Visible := False;
|
|
Poblacion.Properties.Buttons[0].Visible := False;
|
|
Provincia.Properties.Buttons[0].Visible := False;
|
|
|
|
try
|
|
with TablaFacturas do
|
|
begin
|
|
Prepare;
|
|
Open;
|
|
if RecordCount = 0 then
|
|
begin
|
|
VerMensajeFmt(msgCliNoExisteFac, [CodigoFactura]);
|
|
CancelarEliminar;
|
|
CloseFrame;
|
|
Exit;
|
|
end;
|
|
Cancel;
|
|
end;
|
|
|
|
with TablaDetallesFacturas do
|
|
begin
|
|
Close;
|
|
Params.ByName('CODIGOFACTURA').AsString := CodigoFactura;
|
|
Prepare;
|
|
Open;
|
|
Cancel;
|
|
end;
|
|
|
|
with TablaDetallesMem do
|
|
begin
|
|
Close;
|
|
Open;
|
|
Cancel;
|
|
CargarDetalles;
|
|
end;
|
|
|
|
dmTablaFacturasProforma.InicializarTablaFacturas(@TablaFacturas);
|
|
dmTablaFacturasProforma.InicializarTablaDetalles(@TablaDetallesMem);
|
|
DesactivarEventosCampos;
|
|
DesactivarEdicionGridDetalles(gridDetalles);
|
|
cbRecargoEquivalencia.Checked := TablaFacturas.FieldByName('RE').AsFloat > 0;
|
|
RecargoEquivalencia.Enabled := TablaFacturas.FieldByName('RE').AsFloat > 0;
|
|
cbRecargoEquivalencia.Properties.ReadOnly := True;
|
|
Visible := True;
|
|
FechaFactura.SetFocus;
|
|
except
|
|
on E : EIBError do
|
|
TratarExcepcion(E);
|
|
on E : Exception do
|
|
TratarExcepcion(E);
|
|
end;
|
|
end;
|
|
|
|
procedure TfrFacturaProforma.ActivarModoModificar;
|
|
var
|
|
CodPreAlb : String;
|
|
CodCargo : string;
|
|
begin
|
|
dsFactura.AutoEdit := True;
|
|
dsDetallesFacturas.AutoEdit := True;
|
|
pnlBarraGrid.Visible := True;
|
|
|
|
Codigo.Properties.Buttons[0].Visible := True;
|
|
Codigo.Properties.ReadOnly := True;
|
|
CodCliente.Properties.Buttons[0].Visible := True;
|
|
Poblacion.Properties.Buttons[0].Visible := True;
|
|
Provincia.Properties.Buttons[0].Visible := True;
|
|
|
|
try
|
|
with TablaFacturas do
|
|
begin
|
|
Prepare;
|
|
Open;
|
|
FieldByName('PROVINCIA').OnSetText := ProvinciaSetText;
|
|
if RecordCount = 0 then
|
|
begin
|
|
VerMensajeFmt(msgCliNoExisteFacPro, [CodigoFactura]);
|
|
CancelarModificar;
|
|
CloseFrame;
|
|
Exit;
|
|
end;
|
|
|
|
Edit;
|
|
Post;
|
|
Edit;
|
|
end;
|
|
|
|
with TablaDetallesFacturas do
|
|
begin
|
|
Close;
|
|
Params.ByName('CODIGOFACTURA').AsString := CodigoFactura;
|
|
Prepare;
|
|
Open;
|
|
end;
|
|
|
|
with TablaDetallesMem do
|
|
begin
|
|
Close;
|
|
Open;
|
|
CargarDetalles;
|
|
end;
|
|
|
|
dmTablaFacturasProforma.InicializarTablaFacturas(@TablaFacturas);
|
|
dmTablaFacturasProforma.InicializarTablaDetalles(@TablaDetallesMem);
|
|
CalcularTotalFactura;
|
|
ActivarEdicionGridDetalles(gridDetalles);
|
|
FCodigoProvincia := dmTablaProvincias.DarCodigoProvincia(Provincia.Text);
|
|
cbRecargoEquivalencia.Checked := TablaFacturas.FieldByName('RE').AsFloat > 0;
|
|
RecargoEquivalencia.Enabled := TablaFacturas.FieldByName('RE').AsFloat > 0;
|
|
cbRecargoEquivalencia.Properties.ReadOnly := False;
|
|
ActivarEventosCampos;
|
|
Visible := True;
|
|
FechaFactura.SetFocus;
|
|
except
|
|
on E : EIBError do
|
|
begin
|
|
case E.IBErrorCode of
|
|
isc_lock_conflict : begin
|
|
VerMensajeFmt(msgCliFacProBloqueado, [CodigoFactura]);
|
|
CancelarModificar;
|
|
CloseFrame;
|
|
Exit;
|
|
end
|
|
else
|
|
TratarExcepcion(E);
|
|
end;
|
|
end;
|
|
on E : Exception do
|
|
TratarExcepcion(E);
|
|
end;
|
|
end;
|
|
|
|
function TfrFacturaProforma.AnadirDatos: Boolean;
|
|
begin
|
|
try
|
|
CalcularTotalFactura;
|
|
TablaFacturas.Post;
|
|
|
|
BorrarDetallesIB;
|
|
SalvarDetalles;
|
|
|
|
dmTablaFacturasProforma.IncrementarCodigo;
|
|
Commit;
|
|
FCodigoFactura := TablaFacturas.FieldByName('CODIGO').AsString;
|
|
|
|
TablaFacturas.Close;
|
|
TablaDetallesFacturas.Close;
|
|
TablaDetallesMem.Close;
|
|
Result := True;
|
|
except
|
|
on E : EIBError do begin
|
|
if E.IBErrorCode = isc_unique_key_violation then begin
|
|
VerMensajeFmt(msgCliCodFacProRepetido, [Codigo.DataBinding.Field.AsString]);
|
|
TablaFacturas.Edit;
|
|
end
|
|
else
|
|
TratarExcepcion(E);
|
|
end;
|
|
on E : Exception do
|
|
TratarExcepcion(E);
|
|
end;
|
|
end;
|
|
|
|
procedure TfrFacturaProforma.BuscarFactura;
|
|
begin
|
|
if Transaccion = NIL then
|
|
exit;
|
|
|
|
try
|
|
TablaFacturas.DisableControls;
|
|
TablaDetallesFacturas.DisableControls;
|
|
TablaDetallesMem.DisableControls;
|
|
|
|
TablaFacturas.Close;
|
|
TablaDetallesFacturas.Close;
|
|
TablaDetallesMem.Close;
|
|
|
|
// Buscar la fila a tratar si es necesario
|
|
if not EsCadenaVacia(FCodigoFactura) then
|
|
begin
|
|
TablaFacturas.ParamByName('CODIGOEMPRESA').AsInteger := EmpresaActiva.Codigo;
|
|
TablaFacturas.ParamByName('CODIGO').AsString := FCodigoFactura;
|
|
TablaDetallesFacturas.ParamByName('CODIGOEMPRESA').AsInteger := EmpresaActiva.Codigo;
|
|
TablaDetallesFacturas.Params.ByName('CODIGOFACTURA').AsString := FCodigoFactura;
|
|
end;
|
|
TablaFacturas.Prepare;
|
|
TablaFacturas.Open;
|
|
|
|
TablaDetallesFacturas.Prepare;
|
|
TablaDetallesFacturas.Open;
|
|
|
|
TablaDetallesMem.Close;
|
|
TablaDetallesMem.Open;
|
|
CargarDetalles;
|
|
|
|
dmTablaFacturasProforma.InicializarTablaFacturas(@TablaFacturas);
|
|
dmTablaFacturasProforma.InicializarTablaDetalles(@TablaDetallesMem);
|
|
|
|
TablaFacturas.EnableControls;
|
|
TablaDetallesFacturas.EnableControls;
|
|
TablaDetallesMem.EnableControls;
|
|
except
|
|
on E : EIBError do
|
|
TratarExcepcion(E);
|
|
on E : Exception do
|
|
TratarExcepcion(E);
|
|
end;
|
|
end;
|
|
|
|
procedure TfrFacturaProforma.CalcularTotalDetalle;
|
|
var
|
|
auxCantidad,
|
|
auxPrecio,
|
|
auxTotal : double;
|
|
begin
|
|
with TablaDetallesMem do
|
|
begin
|
|
auxCantidad := FieldByName('CANTIDAD').AsFloat;
|
|
auxPrecio := FieldByName('IMPORTEUNIDAD').AsFloat;
|
|
auxTotal := (auxCantidad * auxPrecio);
|
|
FieldByName('IMPORTETOTAL').AsFloat := auxTotal;
|
|
end;
|
|
CalcularTotalFactura;
|
|
end;
|
|
|
|
procedure TfrFacturaProforma.CalcularTotalFactura;
|
|
var
|
|
BaseImponible,
|
|
ImporteRE,
|
|
ImporteIVA,
|
|
ImporteDto,
|
|
ImporteTotal : Double;
|
|
FDetallesBookmark : string;
|
|
begin
|
|
BaseImponible := 0;
|
|
ImporteTotal := 0;
|
|
with TablaDetallesMem do
|
|
begin
|
|
DisableControls;
|
|
FDetallesBookmark := Bookmark;
|
|
try
|
|
First;
|
|
while not EOF do begin
|
|
BaseImponible := BaseImponible + FieldByName('IMPORTETOTAL').AsFloat;
|
|
Next;
|
|
end;
|
|
|
|
ImporteRE := BaseImponible * (TablaFacturas.FieldByName('RE').AsFloat/100);
|
|
ImporteDto := BaseImponible * (TablaFacturas.FieldByName('DESCUENTO').AsFloat/100);
|
|
ImporteTotal := BaseImponible - ImporteDto;
|
|
ImporteIVA := ImporteTotal * (TablaFacturas.FieldByName('IVA').AsFloat/100);
|
|
ImporteTotal := ImporteTotal + ImporteIVA + ImporteRE;
|
|
|
|
TablaFacturas.FieldByName('BASEIMPONIBLE').AsFloat := BaseImponible;
|
|
TablaFacturas.FieldByName('IMPORTEDESCUENTO').AsFloat := ImporteDto;
|
|
TablaFacturas.FieldByName('IMPORTERE').AsFloat := ImporteRE;
|
|
TablaFacturas.FieldByName('IMPORTEIVA').AsFloat := ImporteIVA;
|
|
TablaFacturas.FieldByName('IMPORTETOTAL').AsFloat := ImporteTotal;
|
|
finally
|
|
Bookmark := FDetallesBookmark;
|
|
EnableControls;
|
|
end;
|
|
end;
|
|
end;
|
|
|
|
function TfrFacturaProforma.CancelarAnadir: Boolean;
|
|
begin
|
|
Result := False;
|
|
try
|
|
RollBack;
|
|
TablaDetallesMem.Close;
|
|
TablaFacturas.Close;
|
|
TablaDetallesFacturas.Close;
|
|
Result := True;
|
|
except
|
|
on E : EIBError do
|
|
TratarExcepcion(E);
|
|
on E : Exception do
|
|
TratarExcepcion(E);
|
|
end;
|
|
end;
|
|
|
|
function TfrFacturaProforma.CancelarEliminar: Boolean;
|
|
begin
|
|
Result := False;
|
|
try
|
|
RollBack;
|
|
TablaDetallesMem.Close;
|
|
TablaFacturas.Close;
|
|
TablaDetallesFacturas.Close;
|
|
TablaDetallesMem.Close;
|
|
Result := True;
|
|
except
|
|
on E : EIBError do
|
|
TratarExcepcion(E);
|
|
on E : Exception do
|
|
TratarExcepcion(E);
|
|
end;
|
|
end;
|
|
|
|
function TfrFacturaProforma.CancelarModificar: Boolean;
|
|
begin
|
|
Result := False;
|
|
try
|
|
RollBack;
|
|
TablaDetallesMem.Close;
|
|
TablaFacturas.Close;
|
|
TablaDetallesFacturas.Close;
|
|
Result := True;
|
|
except
|
|
on E : EIBError do
|
|
TratarExcepcion(E);
|
|
on E : Exception do
|
|
TratarExcepcion(E);
|
|
end;
|
|
end;
|
|
|
|
function TfrFacturaProforma.ComprobarDatos: Boolean;
|
|
begin
|
|
Result := False;
|
|
|
|
if EsCadenaVacia(FechaFactura.DataBinding.Field.AsString) then
|
|
begin
|
|
VerMensaje(msgCliFaltaFechaAlta);
|
|
FechaFactura.SetFocus;
|
|
Exit;
|
|
end;
|
|
|
|
if Modo = Anadir then
|
|
begin
|
|
if EsCadenaVacia(CodCliente.DataBinding.Field.AsString) then
|
|
begin
|
|
VerMensaje(msgCliFaltaCodCli);
|
|
Paginas.ActivePageIndex := 0;
|
|
CodCliente.SetFocus;
|
|
Exit;
|
|
end
|
|
end
|
|
else
|
|
begin
|
|
if EsCadenaVacia(Nombre.DataBinding.Field.AsString) then
|
|
begin
|
|
VerMensaje(msgCliFaltaNombreCli);
|
|
Paginas.ActivePageIndex := 0;
|
|
Nombre.SetFocus;
|
|
Exit;
|
|
end
|
|
end;
|
|
|
|
if TablaDetallesMem.IsEmpty then
|
|
begin
|
|
VerMensaje(msgCliFaltaArticulos);
|
|
Paginas.ActivePage := pagContenido;
|
|
gridDetalles.SetFocus;
|
|
Exit;
|
|
end;
|
|
|
|
Result := True;
|
|
end;
|
|
|
|
constructor TfrFacturaProforma.Create(AOwner: TComponent);
|
|
begin
|
|
inherited Create(AOwner);
|
|
Entidad := entFacturaProforma;
|
|
|
|
FCodigoProvincia := NULL;
|
|
FCodigoPoblacion := NULL;
|
|
FCodigoCliente := NULL;
|
|
FCodigoArticulo := NULL;
|
|
|
|
BaseDatos := dmBaseDatos.BD;
|
|
Transaccion := dmBaseDatos.Transaccion;
|
|
dmTablaArticulos.ArtModelo := entArticulo;
|
|
|
|
TablaFacturas := TIBDataSet.Create(Self);
|
|
TablaDetallesFacturas := TIBDataSet.Create(Self);
|
|
TablaDetallesMem := TRxMemoryData.Create(Self);
|
|
|
|
dsFactura.DataSet := TablaFacturas;
|
|
dsDetallesFacturas.DataSet := TablaDetallesMem;
|
|
with TablaFacturas do
|
|
begin
|
|
Database := BaseDatos;
|
|
Transaction := Transaccion;
|
|
SelectSQL.Assign(dmTablaFacturasProforma.sqlConsultarFactura);
|
|
InsertSQL.Assign(dmTablaFacturasProforma.sqlInsertarFactura);
|
|
ModifySQL.Assign(dmTablaFacturasProforma.sqlModificarFactura);
|
|
DeleteSQL.Assign(dmTablaFacturasProforma.sqlEliminarFactura);
|
|
end;
|
|
|
|
with TablaDetallesFacturas do
|
|
begin
|
|
Database := BaseDatos;
|
|
Transaction := Transaccion;
|
|
SelectSQL.Assign(dmTablaFacturasProforma.sqlConsultarGridDetalles);
|
|
InsertSQL.Assign(dmTablaFacturasProforma.sqlInsertarDetalles);
|
|
ModifySQL.Assign(dmTablaFacturasProforma.sqlModificarDetalles);
|
|
DeleteSQL.Assign(dmTablaFacturasProforma.sqlEliminarDetalles);
|
|
end;
|
|
|
|
with TablaDetallesMem do
|
|
begin
|
|
CopyStructure(TablaDetallesFacturas);
|
|
FieldByName('CODIGOFACTURA').Required := False;
|
|
FieldByName('NUMCONCEPTO').Required := False;
|
|
end;
|
|
|
|
dmTablaFacturasProforma.InicializarGridDetalles(gridDetalles);
|
|
cbxFormaPago.Properties.Items := dmTablaFormasPago.DarFormasPago;
|
|
Paginas.ActivePage := pagCliente;
|
|
end;
|
|
|
|
destructor TfrFacturaProforma.Destroy;
|
|
begin
|
|
TablaDetallesMem.Close;
|
|
TablaDetallesMem.Free;
|
|
|
|
TablaFacturas.Close;
|
|
TablaFacturas.UnPrepare;
|
|
TablaFacturas.Free;
|
|
|
|
TablaDetallesFacturas.Close;
|
|
TablaDetallesFacturas.Unprepare;
|
|
TablaDetallesFacturas.Free;
|
|
inherited;
|
|
end;
|
|
|
|
function TfrFacturaProforma.EliminarDatos: Boolean;
|
|
begin
|
|
Result := False;
|
|
|
|
try
|
|
if dmTablaFacturasProforma.EsUltimaFactura(Codigo.DataBinding.Field.AsString) then
|
|
dmTablaFacturasProforma.DecrementarCodigo;
|
|
|
|
TablaFacturas.Delete;
|
|
BorrarDetalles;
|
|
|
|
Commit;
|
|
|
|
TablaFacturas.Close;
|
|
TablaDetallesFacturas.Close;
|
|
TablaDetallesMem.Close;
|
|
Result := True;
|
|
except
|
|
on E : EIBError do
|
|
begin
|
|
case E.IBErrorCode of
|
|
isc_lock_conflict : VerMensajeFmt(msgCliFacProBloqueado, [Codigo.DataBinding.Field.AsString]);
|
|
else
|
|
TratarExcepcion(E);
|
|
end;
|
|
end;
|
|
on E : Exception do
|
|
TratarExcepcion(E);
|
|
end;
|
|
end;
|
|
|
|
procedure TfrFacturaProforma.FreeContenido;
|
|
var
|
|
Contador : integer;
|
|
AListaCodigos : TStringList;
|
|
begin
|
|
if (ContenidoModal is TRdxFrameFacturasProforma) then begin
|
|
CodigoFactura := (ContenidoModal as TRdxFrameFacturasProforma).CodigoFactura;
|
|
ActivarModo;
|
|
end;
|
|
|
|
if (ContenidoModal is TfrArticulos) then
|
|
begin
|
|
//CodigoArticulo := (ContenidoModal as TRdxFrameArticulos).CodigoArticulo;
|
|
|
|
AListaCodigos := (ContenidoModal as TfrArticulos).ListaArticulos;
|
|
for Contador := AListaCodigos.Count - 1 downto 0 do
|
|
begin
|
|
CodigoArticulo := AListaCodigos.Strings[Contador];
|
|
actAnadirConcepto.Execute;
|
|
end;
|
|
TablaDetallesMem.Delete;
|
|
end;
|
|
|
|
if (ContenidoModal is TRdxFrameClientes) then
|
|
CodigoCliente := (ContenidoModal as TRdxFrameClientes).CodigoCliente;
|
|
if (ContenidoModal is TRdxFrameProvincias) then
|
|
CodigoProvincia := (ContenidoModal as TRdxFrameProvincias).CodigoProvincia;
|
|
if (ContenidoModal is TRdxFramePoblaciones) then begin
|
|
CodigoProvincia := (ContenidoModal as TRdxFramePoblaciones).CodigoProvincia;
|
|
CodigoPoblacion := (ContenidoModal as TRdxFramePoblaciones).CodigoPoblacion;
|
|
end;
|
|
inherited FreeContenido;
|
|
end;
|
|
|
|
function TfrFacturaProforma.ModificarDatos: Boolean;
|
|
begin
|
|
Result := False;
|
|
try
|
|
CalcularTotalFactura;
|
|
TablaFacturas.Post;
|
|
BorrarDetallesIB;
|
|
SalvarDetalles;
|
|
Commit;
|
|
|
|
TablaFacturas.Close;
|
|
TablaDetallesFacturas.Close;
|
|
TablaDetallesMem.Close;
|
|
|
|
Result := True;
|
|
except
|
|
on E : EIBError do
|
|
TratarExcepcion(E);
|
|
on E : Exception do
|
|
TratarExcepcion(E);
|
|
end;
|
|
end;
|
|
|
|
procedure TfrFacturaProforma.SetCodigoArticulo(Value: Variant);
|
|
var
|
|
CodigoAux : String;
|
|
DatosArticulo : TDatosArticulo;
|
|
begin
|
|
if (EsCadenaVacia(Value)) then
|
|
begin
|
|
FCodigoArticulo := CodigoAux;
|
|
Exit;
|
|
end;
|
|
|
|
CodigoAux := Trim(Value);
|
|
if (dmTablaArticulos.ValidarCodigo(CodigoAux)) then
|
|
begin
|
|
CodigoAux := dmTablaArticulos.FormatearCodigo(CodigoAux);
|
|
if (dmTablaArticulos.ExisteCodigo(CodigoAux)) then
|
|
FCodigoArticulo := CodigoAux
|
|
else begin
|
|
raise Exception.CreateFmt(msgDatosCodArtNoExiste, [CodigoAux]);
|
|
end;
|
|
end
|
|
else begin
|
|
raise Exception.CreateFmt(msgDatosCodArtIncorrecto, [CodigoAux]);
|
|
Exit;
|
|
end;
|
|
|
|
DatosArticulo := TDatosArticulo.Create(CodigoAux);
|
|
try
|
|
with TablaDetallesMem do
|
|
begin
|
|
Edit;
|
|
FieldByName('CODIGOFACTURA').AsString := Codigo.DataBinding.Field.AsString;
|
|
FieldByName('NUMCONCEPTO').AsString := dmTablaFacturasProforma.FormatearNumConcepto(IntToStr(RecNo));
|
|
FieldByName('CODIGOARTICULO').AsString := DatosArticulo.Codigo;
|
|
FieldByName('DESCRIPCION').AsString := DatosArticulo.Descripcion;
|
|
FieldByName('FAMILIA').AsVariant := DatosArticulo.Familia;
|
|
if EsCadenaVacia(FieldByName('CANTIDAD').AsString) then
|
|
FieldByName('CANTIDAD').AsString := '1';
|
|
Post;
|
|
gridDetalles.Refresh;
|
|
end;
|
|
FCodigoArticulo := Value;
|
|
finally
|
|
DatosArticulo.Free;
|
|
end;
|
|
end;
|
|
|
|
procedure TfrFacturaProforma.SetCodigoCliente(Value: Variant);
|
|
var
|
|
DatosCliente : TDatosCliente;
|
|
CodAux : Variant;
|
|
DireccionElegida : TDireccionElegida;
|
|
NumSucursal : Integer;
|
|
begin
|
|
if EsCadenaVacia(Value) then
|
|
exit;
|
|
|
|
CodAux := Trim(Value);
|
|
if (dmTablaClientes.ValidarCodigo(CodAux)) then begin
|
|
CodAux := dmTablaClientes.FormatearCodigo(CodAux);
|
|
if (dmTablaClientes.ExisteCodigo(CodAux)) then
|
|
FCodigoCliente := CodAux
|
|
else begin
|
|
VerMensajeFmt(msgCliCodCliNoExiste, [CodAux]);
|
|
Paginas.ActivePageIndex := 0;
|
|
CodCliente.SetFocus;
|
|
Exit;
|
|
end;
|
|
end
|
|
else begin
|
|
VerMensajeFmt(msgCliCodCliIncorrecto, [CodAux]);
|
|
Paginas.ActivePageIndex := 0;
|
|
CodCliente.SetFocus;
|
|
Exit;
|
|
end;
|
|
|
|
DatosCliente := TDatosCliente.Create(FCodigoCliente);
|
|
try
|
|
CodCliente.DataBinding.Field.AsString := DatosCliente.Codigo;
|
|
if DatosCliente.Sucursales.Count > 0 then
|
|
begin
|
|
frElegirDireccionCliente := TfrElegirDireccionCliente.Create(Self);
|
|
try
|
|
frElegirDireccionCliente.Cliente := DatosCliente;
|
|
frElegirDireccionCliente.ShowModal;
|
|
DireccionElegida := frElegirDireccionCliente.DireccionSeleccionada;
|
|
NumSucursal := frElegirDireccionCliente.NumSucursal;
|
|
finally
|
|
frElegirDireccionCliente.Free;
|
|
end;
|
|
end
|
|
else
|
|
DireccionElegida := dePrincipal;
|
|
|
|
if DireccionElegida = dePrincipal then
|
|
begin
|
|
NIFCIF.DataBinding.Field.AsString := DatosCliente.Nifcif;
|
|
Nombre.DataBinding.Field.AsString := DatosCliente.Nombre;
|
|
Calle.DataBinding.Field.AsString := DatosCliente.Calle;
|
|
Numero.DataBinding.Field.AsString := DatosCliente.Numero;
|
|
Piso.DataBinding.Field.AsString := DatosCliente.Piso;
|
|
Provincia.DataBinding.Field.AsString := DatosCliente.Provincia;
|
|
FCodigoProvincia := dmTablaProvincias.DarCodigoProvincia(DatosCliente.Provincia);
|
|
Poblacion.DataBinding.Field.AsString := DatosCliente.Poblacion;
|
|
CodigoPostal.DataBinding.Field.AsString := DatosCliente.CodigoPostal;
|
|
Telefono1.DataBinding.Field.AsString := DatosCliente.Telefono1;
|
|
Telefono2.DataBinding.Field.AsString := DatosCliente.Telefono2;
|
|
Movil1.DataBinding.Field.AsString := DatosCliente.Movil1;
|
|
Movil2.DataBinding.Field.AsString := DatosCliente.Movil2;
|
|
Fax.DataBinding.Field.AsString := DatosCliente.Fax;
|
|
PersonaContacto.DataBinding.Field.AsString := DatosCliente.PersonaContacto;
|
|
end
|
|
else begin
|
|
with DatosCliente.Sucursales do
|
|
begin
|
|
NIFCIF.DataBinding.Field.AsString := Sucursal[NumSucursal].Nifcif;
|
|
Nombre.DataBinding.Field.AsString := Sucursal[NumSucursal].Nombre;
|
|
Calle.DataBinding.Field.AsString := Sucursal[NumSucursal].Calle;
|
|
Numero.DataBinding.Field.AsString := Sucursal[NumSucursal].Numero;
|
|
Piso.DataBinding.Field.AsString := Sucursal[NumSucursal].Piso;
|
|
Provincia.DataBinding.Field.AsString := Sucursal[NumSucursal].Provincia;
|
|
FCodigoProvincia := dmTablaProvincias.DarCodigoProvincia(Sucursal[NumSucursal].Provincia);
|
|
Poblacion.DataBinding.Field.AsString := Sucursal[NumSucursal].Poblacion;
|
|
CodigoPostal.DataBinding.Field.AsString := Sucursal[NumSucursal].CodigoPostal;
|
|
Telefono1.DataBinding.Field.AsString := Sucursal[NumSucursal].Telefono1;
|
|
Telefono2.DataBinding.Field.AsString := Sucursal[NumSucursal].Telefono2;
|
|
Movil1.DataBinding.Field.AsString := Sucursal[NumSucursal].Movil1;
|
|
Movil2.DataBinding.Field.AsString := Sucursal[NumSucursal].Movil2;
|
|
Fax.DataBinding.Field.AsString := Sucursal[NumSucursal].Fax;
|
|
PersonaContacto.DataBinding.Field.AsString := Sucursal[NumSucursal].PersonaContacto;
|
|
end;
|
|
end;
|
|
finally
|
|
DatosCliente.Free;
|
|
end;
|
|
end;
|
|
|
|
procedure TfrFacturaProforma.SetCodigoPoblacion(Value: Variant);
|
|
begin
|
|
if (not EsCadenaVacia(Value)) then
|
|
begin
|
|
FCodigoPoblacion := Value;
|
|
Poblacion.DataBinding.Field.AsString := dmTablaPoblaciones.darNombrePoblacion(FCodigoProvincia, FCodigoPoblacion);
|
|
end;
|
|
end;
|
|
|
|
procedure TfrFacturaProforma.SetCodigoProvincia(Value: Variant);
|
|
begin
|
|
if (not EsCadenaVacia(Value)) then
|
|
begin
|
|
FCodigoProvincia := Value;
|
|
Provincia.DataBinding.Field.AsString := dmTablaProvincias.DarNombreProvincia(FCodigoProvincia);
|
|
end;
|
|
end;
|
|
|
|
procedure TfrFacturaProforma.VerModal;
|
|
begin
|
|
if (ContenidoModal is TRdxFramePoblaciones) then
|
|
(ContenidoModal as TRdxFramePoblaciones).CodigoProvincia := CodigoProvincia;
|
|
if (ContenidoModal is TRdxFrameClientes) then
|
|
(ContenidoModal as TRdxFrameClientes).CodigoCliente := CodigoCliente;
|
|
inherited;
|
|
end;
|
|
|
|
procedure TfrFacturaProforma.CantidadDetalleSetText(Sender: TField;
|
|
const Text: String);
|
|
begin
|
|
if EsCadenaVacia(Text) then
|
|
Sender.AsString := '1'
|
|
else
|
|
Sender.AsString := Text;
|
|
CalcularTotalDetalle;
|
|
end;
|
|
|
|
procedure TfrFacturaProforma.CodigoArticuloDetalleSetText(Sender: TField;
|
|
const Text: String);
|
|
var
|
|
Codigo : String;
|
|
begin
|
|
Sender.AsString := Text;
|
|
CodigoArticulo := Text;
|
|
end;
|
|
|
|
procedure TfrFacturaProforma.GridBotonCodigoArticuloClick(Sender: TObject; AButtonIndex: Integer);
|
|
begin
|
|
TablaDetallesMem.Edit;
|
|
ContenidoModal := TfrArticulos.Create(Self);
|
|
gridDetalles.SetFocus;
|
|
end;
|
|
|
|
procedure TfrFacturaProforma.PrecioDetalleSetText(Sender: TField;
|
|
const Text: String);
|
|
begin
|
|
if EsCadenaVacia(Text) then begin
|
|
Sender.AsString := '0';
|
|
exit;
|
|
end;
|
|
|
|
if Entidad = entAbonoCliente then
|
|
begin
|
|
try
|
|
if StrToFloat(Text) > 0
|
|
then begin
|
|
VerMensaje (msgImporteNegativo);
|
|
Sender.AsFloat := (-1) * StrToFloat(Text)
|
|
end
|
|
else Sender.AsString := Text;
|
|
except
|
|
on E : EConvertError do begin
|
|
Sender.AsString := '0'
|
|
end;
|
|
end;
|
|
end
|
|
else
|
|
Sender.AsString := Text;
|
|
CalcularTotalDetalle;
|
|
end;
|
|
|
|
procedure TfrFacturaProforma.CodigoExit(Sender: TObject);
|
|
begin
|
|
if (Modo <> Anadir) or (Visible = false) then
|
|
Exit;
|
|
|
|
if not EsCadenaVacia(Codigo.Text) then
|
|
begin
|
|
if (dmTablaFacturasProforma.validarCodigo(Codigo.Text)) then
|
|
begin
|
|
Codigo.DataBinding.Field.AsString := dmTablaFacturasProforma.FormatearCodigo(Codigo.Text);
|
|
if (dmTablaFacturasProforma.ExisteCodigo(Codigo.Text)) then begin
|
|
VerMensajeFmt(msgCliCodFacProRepetido, [Codigo.Text]);
|
|
Codigo.SetFocus;
|
|
end;
|
|
end
|
|
else begin
|
|
VerMensajeFmt(msgCliCodFacProIncorrecto, [Codigo.Text]);
|
|
Codigo.SetFocus;
|
|
end
|
|
end
|
|
else
|
|
Codigo.DataBinding.Field.AsString := dmTablaFacturasProforma.DarNuevoCodigo;
|
|
end;
|
|
|
|
procedure TfrFacturaProforma.CodClienteExit(Sender: TObject);
|
|
begin
|
|
if not (Modo in [Anadir, Modificar]) then
|
|
Exit;
|
|
end;
|
|
|
|
procedure TfrFacturaProforma.DtoSetText(Sender: TField; const Text: String);
|
|
begin
|
|
if EsCadenaVacia(Text) then
|
|
Sender.AsString := '0'
|
|
else begin
|
|
ValidarDto(Text);
|
|
Sender.AsString := Text;
|
|
end;
|
|
CalcularTotalFactura;
|
|
end;
|
|
|
|
procedure TfrFacturaProforma.IVASetText(Sender: TField; const Text: String);
|
|
begin
|
|
if EsCadenaVacia(Text) then
|
|
Sender.AsString := '0'
|
|
else begin
|
|
ValidarIVA(Text);
|
|
Sender.AsString := Text;
|
|
end;
|
|
CalcularTotalFactura;
|
|
end;
|
|
|
|
procedure TfrFacturaProforma.BorrarDetalles;
|
|
begin
|
|
with TablaDetallesMem do
|
|
begin
|
|
DisableControls;
|
|
EmptyTable;
|
|
EnableControls;
|
|
end;
|
|
end;
|
|
|
|
procedure TfrFacturaProforma.BorrarDetallesIB;
|
|
begin
|
|
with TablaDetallesFacturas do
|
|
begin
|
|
if IsEmpty then
|
|
Exit;
|
|
DisableControls;
|
|
Last;
|
|
while not BOF do
|
|
begin
|
|
Delete;
|
|
Prior;
|
|
end;
|
|
if not IsEmpty then
|
|
Delete;
|
|
EnableControls;
|
|
end;
|
|
end;
|
|
|
|
procedure TfrFacturaProforma.CargarDetalles;
|
|
var
|
|
NumeroCampo : Integer;
|
|
begin
|
|
with TablaDetallesMem do
|
|
begin
|
|
if TablaDetallesFacturas.IsEmpty then
|
|
Exit;
|
|
DisableControls;
|
|
TablaDetallesFacturas.First;
|
|
while not TablaDetallesFacturas.EOF do
|
|
begin
|
|
Append;
|
|
for NumeroCampo := 0 to TablaDetallesFacturas.FieldCount-1 do
|
|
Fields[NumeroCampo].AsString := TablaDetallesFacturas.Fields[NumeroCampo].AsString;
|
|
Post;
|
|
TablaDetallesFacturas.Next;
|
|
end;
|
|
First;
|
|
EnableControls;
|
|
end;
|
|
end;
|
|
|
|
procedure TfrFacturaProforma.SalvarDetalles;
|
|
var
|
|
NumeroCampo : Integer;
|
|
NumConcepto : Integer;
|
|
begin
|
|
try
|
|
with TablaDetallesMem do
|
|
begin
|
|
if IsEmpty then
|
|
Exit;
|
|
NumConcepto := 0;
|
|
DisableControls;
|
|
First;
|
|
while not EOF do
|
|
begin
|
|
TablaDetallesFacturas.Append;
|
|
for NumeroCampo := 0 to FieldCount-1 do
|
|
begin
|
|
if Fields[NumeroCampo].FieldName = 'CODIGOEMPRESA' then
|
|
TablaDetallesFacturas.Fields[NumeroCampo].AsInteger := EmpresaActiva.Codigo
|
|
else if Fields[NumeroCampo].FieldName = 'CODIGOFACTURA' then
|
|
TablaDetallesFacturas.Fields[NumeroCampo].AsString := Codigo.DataBinding.Field.AsString
|
|
else
|
|
if Fields[NumeroCampo].FieldName = 'NUMCONCEPTO' then
|
|
TablaDetallesFacturas.Fields[NumeroCampo].AsString := dmTablaFacturasProforma.FormatearNumConcepto(IntToStr(NumConcepto))
|
|
else
|
|
TablaDetallesFacturas.Fields[NumeroCampo].AsVariant := Fields[NumeroCampo].AsVariant;
|
|
end;
|
|
TablaDetallesFacturas.Post;
|
|
Next;
|
|
NumConcepto := NumConcepto + 1;
|
|
end;
|
|
EnableControls;
|
|
end
|
|
except
|
|
on E : EIBError do begin
|
|
if E.IBErrorCode = isc_unique_key_violation then
|
|
begin
|
|
TablaDetallesFacturas.Delete;
|
|
TablaDetallesMem.EnableControls;
|
|
end;
|
|
raise EIBError.Create(E.SQLCode, E.IBErrorCode, E.Message);
|
|
end;
|
|
end;
|
|
end;
|
|
|
|
procedure TfrFacturaProforma.DetalleAfterDelete(DataSet: TDataSet);
|
|
begin
|
|
CalcularTotalFactura;
|
|
end;
|
|
|
|
procedure TfrFacturaProforma.ProvinciaSetText(Sender: TField;
|
|
const Text: String);
|
|
begin
|
|
FCodigoProvincia := dmTablaProvincias.DarCodigoProvincia(Text);
|
|
Sender.AsString := Text;
|
|
end;
|
|
|
|
procedure TfrFacturaProforma.CodigoPropertiesButtonClick(Sender: TObject;
|
|
AButtonIndex: Integer);
|
|
begin
|
|
if (TratarCambios = IDCANCEL) then
|
|
Exit;
|
|
{ Esto es porque en modo 'Modificar' hacemos un cambio y pulsamos
|
|
este botón se cierra la tabla y si en el frame hijo (el del grid) damos
|
|
a cancelar, FCodigoFactura es NULL y da error al activar modo porque
|
|
no se inicializa los parámetros de la sql. Lo hace BuscarFactura. }
|
|
if not TablaFacturas.Active then
|
|
BuscarFactura;
|
|
ContenidoModal := TfrFacturasClientes.Create(Self);
|
|
end;
|
|
|
|
procedure TfrFacturaProforma.CodClientePropertiesButtonClick(
|
|
Sender: TObject; AButtonIndex: Integer);
|
|
begin
|
|
ContenidoModal := TfrClientes.Create(Self);
|
|
end;
|
|
|
|
procedure TfrFacturaProforma.ProvinciaPropertiesButtonClick(Sender: TObject;
|
|
AButtonIndex: Integer);
|
|
begin
|
|
CaptionModal := msgListaProvincias;
|
|
WidthModal := 280;
|
|
HeightModal := 460;
|
|
ContenidoModal := TfrProvincias.Create(Self);
|
|
end;
|
|
|
|
procedure TfrFacturaProforma.PoblacionPropertiesButtonClick(Sender: TObject;
|
|
AButtonIndex: Integer);
|
|
begin
|
|
if EsCadenaVacia(CodigoProvincia) then
|
|
begin
|
|
VerMensaje(msgSinProvincia);
|
|
Paginas.ActivePageIndex := 0;
|
|
Provincia.SetFocus;
|
|
Exit;
|
|
end;
|
|
CaptionModal := Format(msgListaPoblaciones, [dmTablaProvincias.darNombreProvincia(CodigoProvincia)]);
|
|
WidthModal := 280;
|
|
HeightModal := 460;
|
|
ContenidoModal := TfrPoblaciones.Create(Self);
|
|
end;
|
|
|
|
procedure TfrFacturaProforma.DetallesAfterInsert(DataSet: TDataSet);
|
|
begin
|
|
DataSet.FieldByName('DESCRIPCION').AsString := #13+#13+#13;
|
|
end;
|
|
|
|
procedure TfrFacturaProforma.actAnadirConceptoExecute(Sender: TObject);
|
|
begin
|
|
try
|
|
with TablaDetallesMem do
|
|
begin
|
|
//DisableControls;
|
|
Next;
|
|
if EOF then
|
|
Append
|
|
else begin
|
|
Prior;
|
|
Insert;
|
|
end;
|
|
//EnableControls;
|
|
end;
|
|
Paginas.ActivePage := pagContenido;
|
|
gridDetalles.SetFocus;
|
|
except
|
|
on E : EIBError do
|
|
TratarExcepcion(E);
|
|
on E : Exception do
|
|
TratarExcepcion(E);
|
|
end;
|
|
end;
|
|
|
|
procedure TfrFacturaProforma.actEliminarExecute(Sender: TObject);
|
|
begin
|
|
if (VerMensajePregunta(msgDeseaBorrar) <> IDYES) then
|
|
Exit;
|
|
if TablaDetallesMem.RecordCount = 0 then begin
|
|
{ Hacemos un cancel de la tabla por si el registro actual estuviera
|
|
recien creado }
|
|
TablaDetallesMem.Cancel;
|
|
Exit
|
|
end;
|
|
try
|
|
TablaDetallesMem.Delete;
|
|
except
|
|
on E : EIBError do
|
|
TratarExcepcion(E);
|
|
on E : Exception do
|
|
TratarExcepcion(E);
|
|
end;
|
|
CalcularTotalFactura;
|
|
end;
|
|
|
|
procedure TfrFacturaProforma.actEliminarTodoExecute(Sender: TObject);
|
|
begin
|
|
if (VerMensajePregunta(msgDeseaBorrarTodo) <> IDYES) then
|
|
Exit;
|
|
BorrarDetalles;
|
|
CalcularTotalFactura;
|
|
end;
|
|
|
|
procedure TfrFacturaProforma.ReordenarDetallesMem;
|
|
var
|
|
NumConcepto : Integer;
|
|
CurBookmark: string;
|
|
begin
|
|
try
|
|
with TablaDetallesMem do
|
|
begin
|
|
if IsEmpty then
|
|
Exit;
|
|
NumConcepto := RecordCount;
|
|
DisableControls;
|
|
CurBookmark := Bookmark;
|
|
Last;
|
|
while not BOF do
|
|
begin
|
|
Edit;
|
|
FieldByName('NUMCONCEPTO').AsString := dmTablaFacturasProforma.FormatearNumConcepto(IntToStr(NumConcepto));
|
|
Post;
|
|
Dec(NumConcepto);
|
|
Prior;
|
|
end;
|
|
Bookmark := CurBookmark;
|
|
EnableControls;
|
|
end
|
|
except
|
|
on E : EIBError do begin
|
|
if E.IBErrorCode = isc_unique_key_violation then
|
|
TablaDetallesMem.EnableControls;
|
|
raise EIBError.Create(E.SQLCode, E.IBErrorCode, E.Message);
|
|
end;
|
|
end;
|
|
end;
|
|
|
|
procedure TfrFacturaProforma.IntercambiarDetallesMem(PosCon1,
|
|
PosCon2: Integer);
|
|
var
|
|
NumCon1,
|
|
NumCon2 : Variant;
|
|
begin
|
|
try
|
|
with TablaDetallesMem do
|
|
begin
|
|
DisableControls;
|
|
RecNo := PosCon1;
|
|
NumCon1 := FieldByName('NUMCONCEPTO').AsString;
|
|
RecNo := PosCon2;
|
|
NumCon2 := FieldByName('NUMCONCEPTO').AsString;
|
|
|
|
// Intercambio los concepto
|
|
Edit;
|
|
FieldByName('NUMCONCEPTO').AsString := NumCon1;
|
|
Post;
|
|
RecNo := PosCon1;
|
|
Edit;
|
|
FieldByName('NUMCONCEPTO').AsString := NumCon2;
|
|
Post;
|
|
EnableControls;
|
|
ReordenarDetallesMem;
|
|
end;
|
|
except
|
|
TablaDetallesMem.EnableControls;
|
|
end;
|
|
end;
|
|
|
|
function TfrFacturaProforma.GetCodigoCliente: Variant;
|
|
begin
|
|
if TablaFacturas.Active then
|
|
Result := TablaFacturas.FieldByName('CODIGOCLIENTE').AsVariant
|
|
else
|
|
Result := NULL;
|
|
end;
|
|
|
|
procedure TfrFacturaProforma.cbRecargoEquivalenciaPropertiesChange(
|
|
Sender: TObject);
|
|
begin
|
|
RecargoEquivalencia.Enabled := cbRecargoEquivalencia.Checked;
|
|
if not cbRecargoEquivalencia.Checked then
|
|
begin
|
|
RecargoEquivalencia.DataBinding.Field.Value := Null;
|
|
CalcularTotalFactura;
|
|
end;
|
|
end;
|
|
|
|
procedure TfrFacturaProforma.RESetText(Sender: TField; const Text: String);
|
|
begin
|
|
if EsCadenaVacia(Text) then
|
|
Sender.AsString := '0'
|
|
else begin
|
|
ValidarDto(Text);
|
|
Sender.AsString := Text;
|
|
end;
|
|
CalcularTotalFactura;
|
|
end;
|
|
|
|
procedure TfrFacturaProforma.DesactivarEventosCampos;
|
|
begin
|
|
cbRecargoEquivalencia.Properties.OnChange := NIL;
|
|
|
|
with TablaFacturas do
|
|
begin
|
|
FieldByName('CODIGOCLIENTE').OnSetText := NIL;
|
|
FieldByName('IVA').OnSetText := NIL;
|
|
FieldByName('DESCUENTO').OnSetText := NIL;
|
|
FieldByName('RE').OnSetText := NIL;
|
|
end;
|
|
|
|
with TablaDetallesMem do
|
|
begin
|
|
FieldByName('CODIGOARTICULO').OnSetText := NIL;
|
|
FieldByName('CANTIDAD').OnSetText := NIL;
|
|
FieldByName('IMPORTEUNIDAD').OnSetText := NIL;
|
|
AfterDelete := NIL;
|
|
AfterInsert := NIL;
|
|
end;
|
|
end;
|
|
|
|
procedure TfrFacturaProforma.CodCliSetText(Sender: TField;
|
|
const Text: String);
|
|
begin
|
|
Sender.AsString := Text;
|
|
CodigoCliente := Text;
|
|
end;
|
|
|
|
procedure TfrFacturaProforma.actEliminarUpdate(Sender: TObject);
|
|
begin
|
|
if not (Modo in [Anadir, Modificar]) then
|
|
(Sender as TAction).Enabled := False
|
|
else
|
|
(Sender as TAction).Enabled := not (TablaDetallesMem.RecordCount = 0);
|
|
end;
|
|
|
|
procedure TfrFacturaProforma.actEliminarTodoUpdate(Sender: TObject);
|
|
begin
|
|
if not (Modo in [Anadir, Modificar]) then
|
|
(Sender as TAction).Enabled := False
|
|
else
|
|
(Sender as TAction).Enabled := not (TablaDetallesMem.RecordCount = 0);
|
|
end;
|
|
|
|
end.
|