2007-11-28 17:40:31 +00:00
unit uBizPresupuestosCliente;
interface
uses
Classes, uDADataTable, uDAInterfaces, uROClasses,
schPresupuestosClienteClient_Intf, uDBSelectionListUtils,
uBizContactos, uBizDetallesPresupuestoCliente;
const
BIZ_CLIENT_PRESUPUESTO_CLIENTE = 'Client.PresupuestoCliente' ;
SITUACION_PRESUPUESTO_PENDIENTE = 'PENDIENTE' ;
SITUACION_PRESUPUESTO_ACEPTADO = 'ACEPTADO' ;
SITUACION_PRESUPUESTO_ANULADO = 'ANULADO' ;
2024-08-06 16:17:39 +00:00
SITUACION_PRESUPUESTO_PLANTILLA = 'PLANTILLA' ;
2007-11-28 17:40:31 +00:00
type
2009-07-09 09:23:03 +00:00
2007-11-28 17:40:31 +00:00
IBizPresupuestoCliente = interface( IPresupuestosCliente)
[ '{86A2FAD7-D125-47C2-B0BA-52A42FDFA6F6}' ]
procedure SetCliente( AValue : IBizCliente) ;
function GetCliente : IBizCliente;
property Cliente : IBizCliente read GetCliente write SetCliente;
// Esta propidad es para que el controlador pueda acceder directamente
// a la propiedad Cliente
procedure _SetCliente( AValue : IBizCliente) ;
function _GetCliente : IBizCliente;
property _Cliente : IBizCliente read _GetCliente write _SetCliente;
function GetDetalles: IBizDetallesPresupuestoCliente;
procedure SetDetalles( Value: IBizDetallesPresupuestoCliente) ;
property Detalles: IBizDetallesPresupuestoCliente read GetDetalles write SetDetalles;
procedure CalcularImporteTotal;
2016-07-22 17:05:20 +00:00
procedure AsignarVendedor;
2007-11-28 17:40:31 +00:00
function EsNuevo : Boolean ;
function DarListaSituaciones: TStringList;
end ;
TBizPresupuestoCliente = class( TPresupuestosClienteDataTableRules, IBizPresupuestoCliente, ISeleccionable)
private
procedure CalcularBaseImponible;
procedure CalcularIVA;
2009-06-30 16:39:42 +00:00
procedure CalcularRE;
procedure AsignarTipoIVA ( IDTipoIVA : Integer ) ;
2007-11-28 17:40:31 +00:00
protected
FSeleccionableInterface : ISeleccionable;
FCliente : IBizCliente;
FDetalles : IBizDetallesPresupuestoCliente;
FDetallesLink : TDADataSource;
procedure SetCliente( AValue : IBizCliente) ;
function GetCliente : IBizCliente;
procedure _SetCliente( AValue : IBizCliente) ;
function _GetCliente : IBizCliente;
function GetDetalles: IBizDetallesPresupuestoCliente;
procedure SetDetalles( Value: IBizDetallesPresupuestoCliente) ;
function GetSITUACIONValue: String ; override ;
procedure SetFECHA_PRESUPUESTOValue( const aValue: TDateTime) ; override ;
procedure SetID_FORMA_PAGOValue( const aValue: Integer ) ; override ;
procedure OnNewRecord( Sender: TDADataTable) ; override ;
procedure IniciarValoresPresupuestoNuevo;
2009-06-30 16:39:42 +00:00
procedure RECARGO_EQUIVALENCIAOnChange( Sender: TDACustomField) ;
procedure ID_TIPO_IVAOnChange( Sender: TDACustomField) ;
2007-11-28 17:40:31 +00:00
procedure IMPORTE_NETOOnChange( Sender: TDACustomField) ;
procedure IMPORTE_PORTEOnChange( Sender: TDACustomField) ;
procedure DESCUENTOOnChange( Sender: TDACustomField) ;
procedure IVAOnChange( Sender: TDACustomField) ;
2009-06-30 16:39:42 +00:00
procedure REOnChange( Sender: TDACustomField) ;
procedure SetID_TIPO_IVAValue( const aValue: Integer ) ; override ;
2007-11-28 17:40:31 +00:00
public
function DarListaSituaciones: TStringList;
function EsNuevo : Boolean ;
2016-07-22 17:05:20 +00:00
procedure AsignarVendedor;
2007-11-28 17:40:31 +00:00
procedure CalcularImporteTotal;
property Cliente : IBizCliente read GetCliente write SetCliente;
property _Cliente : IBizCliente read _GetCliente write _SetCliente;
property Detalles: IBizDetallesPresupuestoCliente read GetDetalles write SetDetalles;
property SeleccionableInterface : ISeleccionable read FSeleccionableInterface
write FSeleccionableInterface implements ISeleccionable;
constructor Create( aDataTable: TDADataTable) ; override ;
destructor Destroy; override ;
end ;
implementation
uses
2009-06-30 16:39:42 +00:00
SysUtils, Variants, uDataModuleConfiguracion, uDataModuleUsuarios, Dialogs,
2009-11-05 16:24:35 +00:00
uDataTableUtils, DateUtils, uDateUtils, DB, uFactuGES_App,
uTiposIVAController, uBizTiposIVA, uVendedoresController;
2007-11-28 17:40:31 +00:00
{ TBizPresupuestoCliente }
2009-06-30 16:39:42 +00:00
procedure TBizPresupuestoCliente. AsignarTipoIVA( IDTipoIVA: Integer ) ;
var
ATiposIVAController : ITiposIVAController;
ATipoIVA : IBizTipoIVA;
begin
inherited ;
ATiposIVAController : = TTiposIVAController. Create;
try
ATipoIVA : = ATiposIVAController. Buscar( IDTipoIVA) ;
ATipoIVA. DataTable. Active : = True ;
if Assigned( ATipoIVA) then
begin
Edit;
IVA : = ATipoIVA. IVA;
if ( RECARGO_EQUIVALENCIA = 1 ) then
RE : = ATipoIVA. RE
else
RE : = 0 ;
end ;
finally
ATiposIVAController : = NIL ;
end ;
end ;
2007-11-28 17:40:31 +00:00
procedure TBizPresupuestoCliente. CalcularBaseImponible;
begin
if not Self. DataTable. Editing then
Edit;
IMPORTE_DESCUENTO : = IMPORTE_NETO * ( DESCUENTO/ 1 0 0 ) ;
BASE_IMPONIBLE : = IMPORTE_NETO - IMPORTE_DESCUENTO + IMPORTE_PORTE;
end ;
procedure TBizPresupuestoCliente. CalcularImporteTotal;
begin
DataTable. DisableControls;
DataTable. Fields. FieldEventsDisabled : = True ;
try
CalcularBaseImponible;
CalcularIVA;
2009-06-30 16:39:42 +00:00
CalcularRE;
2007-11-28 17:40:31 +00:00
if not Self. DataTable. Editing then
Edit;
2009-06-30 16:39:42 +00:00
IMPORTE_TOTAL : = BASE_IMPONIBLE + IMPORTE_IVA + IMPORTE_RE;
2007-11-28 17:40:31 +00:00
finally
DataTable. Fields. FieldEventsDisabled : = False ;
DataTable. EnableControls;
end ;
end ;
procedure TBizPresupuestoCliente. CalcularIVA;
begin
if not Self. DataTable. Editing then
Edit;
IMPORTE_IVA : = ( IVA / 1 0 0 ) * ( BASE_IMPONIBLE) ;
end ;
2009-06-30 16:39:42 +00:00
procedure TBizPresupuestoCliente. CalcularRE;
begin
if not Self. DataTable. Editing then
Edit;
IMPORTE_RE : = ( RE / 1 0 0 ) * BASE_IMPONIBLE;
end ;
2007-11-28 17:40:31 +00:00
constructor TBizPresupuestoCliente. Create( aDataTable: TDADataTable) ;
begin
inherited ;
FCliente : = Nil ;
with DataTable do
begin
2009-06-30 16:39:42 +00:00
FieldByName( fld_PresupuestosClienteID_TIPO_IVA) . OnChange : = ID_TIPO_IVAOnChange;
FieldByName( fld_PresupuestosClienteRECARGO_EQUIVALENCIA) . OnChange : = RECARGO_EQUIVALENCIAOnChange;
2007-11-28 17:40:31 +00:00
FieldByName( fld_PresupuestosClienteIMPORTE_NETO) . OnChange : = IMPORTE_NETOOnChange;
FieldByName( fld_PresupuestosClienteIMPORTE_PORTE) . OnChange : = IMPORTE_PORTEOnChange;
FieldByName( fld_PresupuestosClienteDESCUENTO) . OnChange : = DESCUENTOOnChange;
FieldByName( fld_PresupuestosClienteIVA) . OnChange : = IVAOnChange;
2009-06-30 16:39:42 +00:00
FieldByName( fld_PresupuestosClienteRE) . OnChange : = REOnChange;
2007-11-28 17:40:31 +00:00
end ;
FDetallesLink : = TDADataSource. Create( NIL ) ;
FDetallesLink. DataTable : = aDataTable;
FSeleccionableInterface : = TSeleccionable. Create( aDataTable) ;
end ;
function TBizPresupuestoCliente. DarListaSituaciones: TStringList;
begin
Result : = TStringList. Create;
with Result do
begin
Add( SITUACION_PRESUPUESTO_PENDIENTE) ;
Add( SITUACION_PRESUPUESTO_ACEPTADO) ;
Add( SITUACION_PRESUPUESTO_ANULADO) ;
end ;
end ;
procedure TBizPresupuestoCliente. DESCUENTOOnChange( Sender: TDACustomField) ;
begin
CalcularImporteTotal;
end ;
destructor TBizPresupuestoCliente. Destroy;
begin
FCliente : = NIL ;
FDetalles : = NIL ;
FDetallesLink. Free;
FSeleccionableInterface : = NIL ;
inherited ;
end ;
2009-11-05 16:24:35 +00:00
procedure TBizPresupuestoCliente. AsignarVendedor;
var
AVendedoresController: IVendedoresController;
begin
AVendedoresController : = TVendedoresController. Create;
try
2009-11-24 17:42:50 +00:00
ID_VENDEDOR : = AVendedoresController. DarIDVendedorDeUsuario( AppFactuGES. UsuarioActivo. ID) ;
2009-11-05 16:24:35 +00:00
finally
AVendedoresController : = nil ;
end ;
end ;
2007-11-28 17:40:31 +00:00
function TBizPresupuestoCliente. EsNuevo: Boolean ;
begin
Result : = ( ID < 0 ) ;
end ;
function TBizPresupuestoCliente. GetCliente: IBizCliente;
begin
Result : = FCliente;
end ;
2009-06-30 16:39:42 +00:00
procedure TBizPresupuestoCliente. ID_TIPO_IVAOnChange( Sender: TDACustomField) ;
begin
AsignarTipoIVA( ID_TIPO_IVA) ;
end ;
2007-11-28 17:40:31 +00:00
procedure TBizPresupuestoCliente. IMPORTE_NETOOnChange( Sender: TDACustomField) ;
begin
CalcularImporteTotal;
end ;
procedure TBizPresupuestoCliente. IMPORTE_PORTEOnChange( Sender: TDACustomField) ;
begin
CalcularImporteTotal;
end ;
procedure TBizPresupuestoCliente. IniciarValoresPresupuestoNuevo;
begin
ID_EMPRESA : = AppFactuGES. EmpresaActiva. ID;
USUARIO : = AppFactuGES. UsuarioActivo. UserName;
2009-06-30 16:39:42 +00:00
ID_FORMA_PAGO : = AppFactuGES. EmpresaActiva. ID_FORMA_PAGO;
ID_TIPO_IVA : = AppFactuGES. EmpresaActiva. ID_TIPO_IVA;
2007-11-28 17:40:31 +00:00
FECHA_PRESUPUESTO : = DateOf( Date) ;
2009-06-30 16:39:42 +00:00
FECHA_VIGENCIA : = IncMonth( Date, AppFactuGES. EmpresaActiva. VALIDEZ_PRESUPUESTOS) ;
2024-08-06 16:17:39 +00:00
FECHA_ULT_PRESENTACION_CLIENTE : = DateOf( Date) ;
2009-11-24 12:23:14 +00:00
NO_VALORADO : = 0 ;
2007-11-28 17:40:31 +00:00
INCIDENCIAS_ACTIVAS : = 0 ;
2009-06-30 16:39:42 +00:00
RE : = 0 ;
2007-11-28 17:40:31 +00:00
REFERENCIA : = '' ;
SITUACION : = SITUACION_PRESUPUESTO_PENDIENTE;
2009-06-30 16:39:42 +00:00
2008-07-23 16:46:26 +00:00
ID_TIENDA : = AppFactuGES. TiendaActiva. ID;
TIENDA : = AppFactuGES. TiendaActiva. NOMBRE;
2009-09-22 09:10:49 +00:00
Self. DataTable. FieldByName( fld_PresupuestosClienteFORMA_PAGO) . AsString : = AppFactuGES. FormaPagoDocumentos;
Self. DataTable. FieldByName( fld_PresupuestosClienteOBSERVACIONES) . AsString : = AppFactuGES. ObservacionesDocumentos;
2014-02-05 15:58:08 +00:00
// Self.DataTable.FieldByName(fld_PresupuestosClienteCALIDADES).AsString := AppFactuGES.CalidadesDocumentos;
2013-11-12 18:13:29 +00:00
2009-11-05 16:24:35 +00:00
AsignarVendedor;
2007-11-28 17:40:31 +00:00
end ;
procedure TBizPresupuestoCliente. IVAOnChange( Sender: TDACustomField) ;
begin
CalcularImporteTotal;
end ;
function TBizPresupuestoCliente. GetDetalles: IBizDetallesPresupuestoCliente;
begin
Result : = FDetalles;
end ;
function TBizPresupuestoCliente. GetSITUACIONValue: String ;
begin
result : = Trim( DataTable. Fields[ idx_PresupuestosClienteSITUACION] . AsString) ;
end ;
procedure TBizPresupuestoCliente. OnNewRecord( Sender: TDADataTable) ;
begin
inherited ;
// ID := GetRecNo; // -1, -2, -3...
IniciarValoresPresupuestoNuevo;
end ;
2009-06-30 16:39:42 +00:00
procedure TBizPresupuestoCliente. RECARGO_EQUIVALENCIAOnChange(
Sender: TDACustomField) ;
begin
AsignarTipoIVA( ID_TIPO_IVA) ;
end ;
procedure TBizPresupuestoCliente. REOnChange( Sender: TDACustomField) ;
begin
CalcularImporteTotal;
end ;
2007-11-28 17:40:31 +00:00
procedure TBizPresupuestoCliente. SetCliente( AValue: IBizCliente) ;
var
bEnEdicion : Boolean ;
begin
FCliente : = AValue;
if Assigned( FCliente) then
begin
if not FCliente. DataTable. Active then
FCliente. DataTable. Active : = True ;
if ID_Cliente < > FCliente. ID then
begin
bEnEdicion : = ( DataTable. State in dsEditModes) ;
if not bEnEdicion then
DataTable. Edit;
ID_CLIENTE : = FCliente. ID;
2008-11-27 09:53:20 +00:00
if FCliente. ID_FORMA_PAGO > 0 then
ID_FORMA_PAGO : = FCliente. ID_FORMA_PAGO;
2023-10-19 16:45:23 +00:00
2024-08-06 16:17:39 +00:00
//OJO en empresa cristina no existen tiendas solo es la tienda cristina por lo que no se cambia asignaci<63> n si estamos en esa empresa, falla si de cogen un cliente de acana los contadores
if ( AppFactuGES. EmpresaActiva. ID < > CTE_EMPRESA_CRISTINA)
and ( FCliente. ID_TIENDA > 0 ) then
2023-10-19 16:45:23 +00:00
begin
ID_TIENDA : = FCliente. ID_TIENDA;
TIENDA : = FCliente. TIENDA;
end ;
2024-08-06 16:17:39 +00:00
// En acana la ficha de cliente no tiene descuento aplicado por defecto
2009-06-30 16:39:42 +00:00
// DESCUENTO := FCliente.DESCUENTO;
2007-11-28 17:40:31 +00:00
DataTable. Post; //Muy importante ya que es necesario hacer un post de la cabecera antes de a<> adir detalles
//si se quita el id de la cabecera y los detalles se desincroniza
if bEnEdicion then
DataTable. Edit;
end ;
end ;
end ;
procedure TBizPresupuestoCliente. SetDetalles( Value: IBizDetallesPresupuestoCliente) ;
begin
FDetalles : = Value;
EnlazarMaestroDetalle( FDetallesLink, FDetalles) ;
end ;
procedure TBizPresupuestoCliente. SetFECHA_PRESUPUESTOValue( const aValue: TDateTime) ;
begin
if EsFechaVacia( aValue) then
SetFieldNull( DataTable, fld_PresupuestosClienteFECHA_PRESUPUESTO)
else
inherited ;
end ;
procedure TBizPresupuestoCliente. SetID_FORMA_PAGOValue( const aValue: Integer ) ;
begin
if ( aValue = 0 ) then
SetFieldNull( DataTable, fld_PresupuestosClienteID_FORMA_PAGO)
else
inherited ;
end ;
2009-06-30 16:39:42 +00:00
procedure TBizPresupuestoCliente. SetID_TIPO_IVAValue( const aValue: Integer ) ;
begin
if ( aValue = 0 ) then
SetFieldNull( DataTable, fld_PresupuestosClienteID_TIPO_IVA)
else
inherited ;
end ;
2007-11-28 17:40:31 +00:00
{
procedure TBizPresupuestoCliente. SetINCIDENCIASValue( const aValue: IROStrings) ;
begin
if not Assigned( aValue) then
SetFieldNull( DataTable, fld_PresupuestosClienteINCIDENCIAS)
else
inherited ;
end ;
}
function TBizPresupuestoCliente. _GetCliente: IBizCliente;
begin
Result : = FCliente;
end ;
procedure TBizPresupuestoCliente. _SetCliente( AValue: IBizCliente) ;
begin
FCliente : = AValue;
end ;
initialization
RegisterDataTableRules( BIZ_CLIENT_PRESUPUESTO_CLIENTE, TBizPresupuestoCliente) ;
finalization
end .