2011-11-14 17:40:41 +00:00
unit uViewFacturaCliente;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, uViewBase, DB, uDADataTable, uCustomView,
uViewDatosYSeleccionCliente, uBizFacturasCliente,
cxControls, cxContainer, cxEdit, cxTextEdit, cxDBEdit, dxLayoutControl,
cxMemo, cxMaskEdit, cxDropDownEdit, cxCalendar, cxSpinEdit, StdCtrls, Mask,
DBCtrls, cxGraphics, dxLayoutLookAndFeels, cxLookupEdit, cxDBLookupEdit,
cxDBLookupComboBox, uFormasPagoController, uDAInterfaces, uBizFormasPago,
uViewTienda, uFacturasClienteController, uViewClienteFactura, Menus, StdActns,
2023-12-04 14:04:07 +00:00
ActnList, uViewObservaciones, cxCheckBox, uViewDatosYSeleccionComercial,
uViewDatosYSeleccionContrato;
2011-11-14 17:40:41 +00:00
type
IViewFacturaCliente = interface( IViewBase)
[ '{3A95930C-20B3-41E9-93CB-21138ADB5B70}' ]
function GetController : IFacturasClienteController;
procedure SetController ( const Value : IFacturasClienteController) ;
property Controller : IFacturasClienteController read GetController write SetController;
function GetFactura: IBizFacturaCliente;
procedure SetFactura( const Value: IBizFacturaCliente) ;
property Factura: IBizFacturaCliente read GetFactura write SetFactura;
end ;
TfrViewFacturaCliente = class( TfrViewBase, IViewFacturaCliente)
DADataSource: TDADataSource;
dxLayoutControl1Group_Root: TdxLayoutGroup;
dxLayoutControl1: TdxLayoutControl;
dxLayoutControl1Item1: TdxLayoutItem;
eReferencia: TcxDBTextEdit;
dxLayoutControl1Item2: TdxLayoutItem;
edtFecha: TcxDBDateEdit;
dxLayoutControl1Group1: TdxLayoutGroup;
dxLayoutControl1Group2: TdxLayoutGroup;
dxLayoutControl1Group5: TdxLayoutGroup;
dxLayoutLookAndFeelList1: TdxLayoutLookAndFeelList;
dxLayoutOfficeLookAndFeel1: TdxLayoutOfficeLookAndFeel;
dsFormaPago: TDADataSource;
dxLayoutControl1Item4: TdxLayoutItem;
cbFormaPago: TcxDBLookupComboBox;
dxLayoutControl1Item10: TdxLayoutItem;
bFormasPago: TButton;
dxLayoutControl1Group6: TdxLayoutGroup;
frViewTienda1: TfrViewTienda;
dxLayoutControl1Group4: TdxLayoutGroup;
dxLayoutControl1Item3: TdxLayoutItem;
dxLayoutControl1Item6: TdxLayoutItem;
frViewClienteFactura1: TfrViewClienteFactura;
dxLayoutControl1Group8: TdxLayoutGroup;
ledtFechaVencimiento: TdxLayoutItem;
edtFechaVencimiento: TcxDBDateEdit;
dxLayoutControl1Group3: TdxLayoutGroup;
frViewObservaciones1: TfrViewObservaciones;
dxLayoutControl1Item5: TdxLayoutItem;
dxLayoutControl1Item7: TdxLayoutItem;
cbRecargoEquivalencia: TcxDBCheckBox;
dxLayoutControl1Group9: TdxLayoutGroup;
2012-02-07 17:19:35 +00:00
edtSituacion: TcxDBComboBox;
2013-05-30 09:06:45 +00:00
ledtSituacion: TdxLayoutItem;
2022-06-23 15:49:41 +00:00
dxLayoutControl1Item11: TdxLayoutItem;
cbTipoFactura: TcxDBLookupComboBox;
dsTiposFactura: TDADataSource;
2023-02-10 17:16:11 +00:00
dxLayoutControl1Item12: TdxLayoutItem;
frViewDatosYSeleccionComercial1: TfrViewDatosYSeleccionComercial;
dxLayoutControl1Group10: TdxLayoutGroup;
2023-12-04 14:04:07 +00:00
dxLayoutControl1Item13: TdxLayoutItem;
frViewDatosYSeleccionContrato1: TfrViewDatosYSeleccionContrato;
2011-11-14 17:40:41 +00:00
procedure bFormasPagoClick( Sender: TObject) ;
procedure CustomViewDestroy( Sender: TObject) ;
procedure CustomViewCreate( Sender: TObject) ;
2013-05-30 09:06:45 +00:00
procedure cbFormaPagoPropertiesEditValueChanged( Sender: TObject) ;
2011-11-14 17:40:41 +00:00
procedure edtFechaVencimientoPropertiesEditValueChanged( Sender: TObject) ;
protected
FFactura : IBizFacturaCliente;
FController : IFacturasClienteController;
2022-06-23 15:49:41 +00:00
FTiposFacturaCliente : IBizTiposFacturaCliente;
2011-11-14 17:40:41 +00:00
FFormasPago : IBizFormaPago;
FFormasPagoController : IFormasPagoController;
function GetFactura: IBizFacturaCliente;
procedure SetFactura( const Value: IBizFacturaCliente) ;
function GetController : IFacturasClienteController;
procedure SetController ( const Value : IFacturasClienteController) ;
2023-02-10 17:16:11 +00:00
procedure OnComercialChanged( Sender : TObject) ;
2023-12-04 14:04:07 +00:00
procedure OnContratoChanged( Sender: TObject) ;
2023-02-10 17:16:11 +00:00
2011-11-14 17:40:41 +00:00
public
property Factura: IBizFacturaCliente read GetFactura write SetFactura;
property Controller : IFacturasClienteController read GetController write SetController;
end ;
implementation
uses
2023-02-10 17:16:11 +00:00
DateUtils, uDataModuleContactos, schFacturasClienteClient_Intf, uFactuGES_App;
2011-11-14 17:40:41 +00:00
{$R *.dfm}
{ TfrViewFacturaCliente }
procedure TfrViewFacturaCliente. bFormasPagoClick( Sender: TObject) ;
begin
inherited ;
if Assigned( FFormasPago) then
FFormasPagoController. VerTodos( FFormasPago) ;
end ;
procedure TfrViewFacturaCliente. CustomViewCreate( Sender: TObject) ;
begin
inherited ;
FFormasPago : = Nil ;
2022-06-23 15:49:41 +00:00
FTiposFacturaCliente : = Nil ;
2011-11-14 17:40:41 +00:00
FFormasPagoController : = TFormasPagoController. Create;
2013-06-07 16:09:30 +00:00
cbFormaPago. Properties. OnEditValueChanged : = cbFormaPagoPropertiesEditValueChanged;
edtFechaVencimiento. Properties. OnEditValueChanged : = edtFechaVencimientoPropertiesEditValueChanged;
2023-02-10 17:16:11 +00:00
//FILTRO DE EMPRESAS
if ( AppFactuGES. EmpresaActiva. ID = CTE_EMPRESA_ABETO) then
begin
dxLayoutControl1Group10. Visible : = true ;
end
else
begin
dxLayoutControl1Group10. Visible : = false ;
end ;
2011-11-14 17:40:41 +00:00
end ;
procedure TfrViewFacturaCliente. CustomViewDestroy( Sender: TObject) ;
begin
2023-02-10 17:16:11 +00:00
frViewDatosYSeleccionComercial1. OnComercialChanged : = Nil ;
2023-12-04 14:04:07 +00:00
frViewDatosYSeleccionContrato1. OnContratoChanged : = Nil ;
2011-11-14 17:40:41 +00:00
FFormasPago : = Nil ;
2022-06-23 15:49:41 +00:00
FTiposFacturaCliente : = Nil ;
2011-11-14 17:40:41 +00:00
FFormasPagoController : = NIL ;
2013-06-03 16:01:08 +00:00
edtFechaVencimiento. Properties. OnEditValueChanged : = Nil ;
2013-05-30 09:06:45 +00:00
cbFormaPago. Properties. OnEditValueChanged : = Nil ;
inherited ;
2011-11-14 17:40:41 +00:00
end ;
2013-05-30 09:06:45 +00:00
procedure TfrViewFacturaCliente. edtFechaVencimientoPropertiesEditValueChanged(
Sender: TObject) ;
2011-11-14 17:40:41 +00:00
begin
2013-05-30 09:06:45 +00:00
inherited ;
if Assigned( Factura) and ( Factura. DataTable. State in dsEditModes) then
begin
2013-06-03 16:01:08 +00:00
if ( edtFechaVencimiento. EditValue < > null) then
2013-05-30 09:06:45 +00:00
begin
2013-06-03 17:35:26 +00:00
if ( edtFechaVencimiento. EditValue = 0 ) then
begin
Factura. DataTable. DisableEventHandlers;
try
Factura. DataTable. FieldByName( fld_FacturasClienteFECHA_VENCIMIENTO) . Clear;
finally
Factura. DataTable. EnableEventHandlers;
end ;
end
else begin
Application. MessageBox( 'Ha elegido una fecha de vencimiento, la situaci<63> n de la factura vendr<64> dada por la situaci<63> n del recibo generado con el vencimiento dado' , 'Atenci<63> n' , MB_OK) ;
edtSituacion. EditValue : = CTE_PENDIENTE;
ledtSituacion. Enabled : = False ;
end ;
2013-05-30 09:06:45 +00:00
end
2013-06-03 17:35:26 +00:00
else begin
2013-05-30 09:06:45 +00:00
// edtSituacion.EditValue := CTE_PENDIENTE;
ledtSituacion. Enabled : = True ;
end ;
end ;
end ;
procedure TfrViewFacturaCliente. cbFormaPagoPropertiesEditValueChanged( Sender: TObject) ;
begin
if Assigned( Factura) and ( Factura. DataTable. State in dsEditModes) then
begin
if Assigned( FFormasPago) then
if ( FFormasPago. Plazos. RecordCount = 0 ) then
begin
// edtFechaVencimiento.EditValue := DateOf(Now);
ledtFechaVencimiento. Enabled : = True ;
edtSituacion. EditValue : = CTE_PENDIENTE;
ledtSituacion. Enabled : = True ;
end
else
begin
Application. MessageBox( 'Ha elegido una forma de pago con plazos asignados, la situaci<63> n de la factura vendr<64> dada por la situaci<63> n de los recibos generados seg<65> n los plazos' , 'Atenci<63> n' , MB_OK) ;
edtFechaVencimiento. EditValue : = Null;
ledtFechaVencimiento. Enabled : = False ;
edtSituacion. EditValue : = CTE_PENDIENTE;
ledtSituacion. Enabled : = False ;
end ;
end ;
2011-11-14 17:40:41 +00:00
end ;
function TfrViewFacturaCliente. GetController: IFacturasClienteController;
begin
Result : = FController;
end ;
function TfrViewFacturaCliente. GetFactura: IBizFacturaCliente;
begin
Result : = FFactura;
end ;
2023-02-10 17:16:11 +00:00
procedure TfrViewFacturaCliente. OnComercialChanged( Sender: TObject) ;
begin
if Assigned( FFactura) then
begin
FController. CambiarComercial( FFactura, frViewDatosYSeleccionComercial1. Comercial) ;
end ;
end ;
2023-12-04 14:04:07 +00:00
procedure TfrViewFacturaCliente. OnContratoChanged( Sender: TObject) ;
begin
if Assigned( FFactura) then
begin
FController. CambiarContrato( FFactura, frViewDatosYSeleccionContrato1. Contrato) ;
end ;
end ;
2011-11-14 17:40:41 +00:00
procedure TfrViewFacturaCliente. SetController( const Value: IFacturasClienteController) ;
begin
FController : = Value;
if Assigned( FController) then
frViewClienteFactura1. Controller : = FController. ClienteController;
end ;
procedure TfrViewFacturaCliente. SetFactura( const Value: IBizFacturaCliente) ;
var
ACadena : String ;
begin
FFactura : = Value;
if Assigned( FFactura) then
begin
DADataSource. DataTable : = FFactura. DataTable;
frViewTienda1. DataItem : = FFactura. DataTable;
2023-12-04 14:04:07 +00:00
frViewDatosYSeleccionContrato1. DataItem : = FFactura. DataTable;
frViewDatosYSeleccionContrato1. IdContrato : = FFactura. ID_CONTRATO;
frViewDatosYSeleccionContrato1. OnContratoChanged : = OnContratoChanged;
2024-02-05 10:15:29 +00:00
frViewDatosYSeleccionComercial1. ID_Comercial : = FFactura. ID_AGENTE;
2023-12-04 14:04:07 +00:00
frViewDatosYSeleccionComercial1. OnComercialChanged : = OnComercialChanged;
2011-11-14 17:40:41 +00:00
FFormasPago : = FFormasPagoController. BuscarTodos;
dsFormaPago. DataTable : = FFormasPago. DataTable;
dsFormaPago. DataTable. Active : = True ;
//Posicionamos la tabla en la forma de pago que tiene la factura ya que no lo hace el componente por si solo
FFormasPago. DataTable. Locate( fld_FacturasClienteID, FFactura. ID_FORMA_PAGO, [ ] ) ;
2013-05-30 09:06:45 +00:00
if ( ( not FFactura. FECHA_VENCIMIENTOIsNull) or ( FFormasPago. Plazos. RecordCount > 0 ) ) then
begin
if ( edtFechaVencimiento. EditingValue < > null) then
ledtSituacion. Enabled : = False ;
if ( FFormasPago. Plazos. RecordCount > 0 ) then
ledtFechaVencimiento. Enabled : = False
else
ledtFechaVencimiento. Enabled : = true ;
end
2011-11-14 17:40:41 +00:00
else
2013-05-30 09:06:45 +00:00
begin
ledtFechaVencimiento. Enabled : = True ;
ledtSituacion. Enabled : = True ;
end ;
2011-11-14 17:40:41 +00:00
2022-06-23 15:49:41 +00:00
FTiposFacturaCliente : = FController. darTiposFacturaCliente;
dsTiposFactura. DataTable : = FTiposFacturaCliente. DataTable;
dsTiposFactura. DataTable. Active : = True ;
2011-11-14 17:40:41 +00:00
//Solo se deshabilita al insertar, luego la referencia ser<65> modificable
//eReferencia.Enabled := (FFactura.DataTable.State = dsInsert);
if FFactura. TIPO = CTE_TIPO_ABONO then
begin
dxLayoutControl1Group1. Caption : = 'Datos del abono:' ;
dxLayoutControl1Item2. Caption : = 'Fecha del abono:' ;
ACadena : = 'Elija el cliente al que se le realizar<61> el abono.' ;
end
else
ACadena : = 'Elija el cliente al que se le realizar<61> la factura.' ;
frViewClienteFactura1. MsgElegirCliente : = ACadena;
end
else begin
DADataSource. DataTable : = NIL ;
dsFormaPago. DataTable : = NIL ;
frViewClienteFactura1. Cliente : = NIL
end ;
end ;
end .