2007-10-26 18:19:55 +00:00
|
|
|
|
unit uBizPresupuestosCliente;
|
|
|
|
|
|
|
|
|
|
|
|
interface
|
|
|
|
|
|
|
|
|
|
|
|
uses
|
|
|
|
|
|
Classes, uDADataTable, uDAInterfaces, uROClasses,
|
2007-11-05 17:49:11 +00:00
|
|
|
|
schPresupuestosClienteClient_Intf, uDBSelectionListUtils,
|
2007-10-26 18:19:55 +00:00
|
|
|
|
uBizContactos, uBizDetallesPresupuestoCliente;
|
|
|
|
|
|
|
|
|
|
|
|
const
|
2007-11-05 17:49:11 +00:00
|
|
|
|
BIZ_CLIENT_PRESUPUESTO_CLIENTE = 'Client.PresupuestoCliente';
|
2007-10-26 18:19:55 +00:00
|
|
|
|
|
2007-11-05 17:49:11 +00:00
|
|
|
|
SITUACION_PRESUPUESTO_PENDIENTE = 'PENDIENTE';
|
|
|
|
|
|
SITUACION_PRESUPUESTO_ACEPTADO = 'ACEPTADO';
|
|
|
|
|
|
SITUACION_PRESUPUESTO_ANULADO = 'ANULADO';
|
2007-10-26 18:19:55 +00:00
|
|
|
|
|
|
|
|
|
|
type
|
2007-11-05 17:49:11 +00:00
|
|
|
|
IBizPresupuestoCliente = interface(IPresupuestosCliente)
|
2007-10-26 18:19:55 +00:00
|
|
|
|
['{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;
|
|
|
|
|
|
|
|
|
|
|
|
function EsNuevo : Boolean;
|
|
|
|
|
|
function DarListaSituaciones: TStringList;
|
|
|
|
|
|
end;
|
|
|
|
|
|
|
2007-11-05 17:49:11 +00:00
|
|
|
|
TBizPresupuestoCliente = class(TPresupuestosClienteDataTableRules, IBizPresupuestoCliente, ISeleccionable)
|
2007-10-26 18:19:55 +00:00
|
|
|
|
private
|
|
|
|
|
|
procedure CalcularBaseImponible;
|
|
|
|
|
|
procedure CalcularIVA;
|
|
|
|
|
|
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);
|
|
|
|
|
|
|
2007-11-12 19:36:34 +00:00
|
|
|
|
function GetSITUACIONValue: String; override;
|
2007-11-05 17:49:11 +00:00
|
|
|
|
procedure SetFECHA_PRESUPUESTOValue(const aValue: TDateTime); override;
|
2007-10-26 18:19:55 +00:00
|
|
|
|
procedure SetID_FORMA_PAGOValue(const aValue: Integer); override;
|
|
|
|
|
|
|
|
|
|
|
|
procedure OnNewRecord(Sender: TDADataTable); override;
|
2007-11-05 17:49:11 +00:00
|
|
|
|
procedure IniciarValoresPresupuestoNuevo;
|
2007-10-26 18:19:55 +00:00
|
|
|
|
|
|
|
|
|
|
procedure IMPORTE_NETOOnChange(Sender: TDACustomField);
|
2008-11-11 18:56:40 +00:00
|
|
|
|
procedure IMPORTE_BONIFICACIONOnChange(Sender: TDACustomField);
|
2007-10-26 18:19:55 +00:00
|
|
|
|
procedure IMPORTE_PORTEOnChange(Sender: TDACustomField);
|
|
|
|
|
|
procedure DESCUENTOOnChange(Sender: TDACustomField);
|
|
|
|
|
|
procedure IVAOnChange(Sender: TDACustomField);
|
|
|
|
|
|
|
|
|
|
|
|
public
|
|
|
|
|
|
function DarListaSituaciones: TStringList;
|
|
|
|
|
|
function EsNuevo : Boolean;
|
|
|
|
|
|
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
|
2007-11-05 17:49:11 +00:00
|
|
|
|
SysUtils, Variants, uDataModuleConfiguracion, uDataModuleUsuarios, Dialogs,
|
2007-11-18 15:07:51 +00:00
|
|
|
|
uDataTableUtils, DateUtils, uDateUtils, DB, uFactuGES_App;
|
2007-10-26 18:19:55 +00:00
|
|
|
|
|
|
|
|
|
|
{ TBizPresupuestoCliente }
|
|
|
|
|
|
|
|
|
|
|
|
procedure TBizPresupuestoCliente.CalcularBaseImponible;
|
|
|
|
|
|
begin
|
|
|
|
|
|
if not Self.DataTable.Editing then
|
|
|
|
|
|
Edit;
|
|
|
|
|
|
IMPORTE_DESCUENTO := IMPORTE_NETO * (DESCUENTO/100);
|
2008-11-11 18:56:40 +00:00
|
|
|
|
BASE_IMPONIBLE := IMPORTE_NETO - IMPORTE_DESCUENTO - IMPORTE_BONIFICACION + IMPORTE_PORTE;
|
2007-10-26 18:19:55 +00:00
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
|
|
procedure TBizPresupuestoCliente.CalcularImporteTotal;
|
|
|
|
|
|
begin
|
|
|
|
|
|
DataTable.DisableControls;
|
|
|
|
|
|
DataTable.Fields.FieldEventsDisabled := True;
|
|
|
|
|
|
try
|
|
|
|
|
|
CalcularBaseImponible;
|
|
|
|
|
|
CalcularIVA;
|
|
|
|
|
|
|
|
|
|
|
|
if not Self.DataTable.Editing then
|
|
|
|
|
|
Edit;
|
|
|
|
|
|
IMPORTE_TOTAL := BASE_IMPONIBLE + IMPORTE_IVA;
|
|
|
|
|
|
finally
|
|
|
|
|
|
DataTable.Fields.FieldEventsDisabled := False;
|
|
|
|
|
|
DataTable.EnableControls;
|
|
|
|
|
|
end;
|
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
|
|
procedure TBizPresupuestoCliente.CalcularIVA;
|
|
|
|
|
|
begin
|
|
|
|
|
|
if not Self.DataTable.Editing then
|
|
|
|
|
|
Edit;
|
|
|
|
|
|
IMPORTE_IVA := (IVA / 100) * (BASE_IMPONIBLE);
|
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
|
|
constructor TBizPresupuestoCliente.Create(aDataTable: TDADataTable);
|
|
|
|
|
|
begin
|
|
|
|
|
|
inherited;
|
|
|
|
|
|
FCliente := Nil;
|
|
|
|
|
|
|
|
|
|
|
|
with DataTable do
|
|
|
|
|
|
begin
|
2007-11-05 17:49:11 +00:00
|
|
|
|
FieldByName(fld_PresupuestosClienteIMPORTE_NETO).OnChange := IMPORTE_NETOOnChange;
|
2008-11-11 18:56:40 +00:00
|
|
|
|
FieldByName(fld_PresupuestosClienteIMPORTE_BONIFICACION).OnChange := IMPORTE_BONIFICACIONOnChange;
|
2007-11-05 17:49:11 +00:00
|
|
|
|
FieldByName(fld_PresupuestosClienteIMPORTE_PORTE).OnChange := IMPORTE_PORTEOnChange;
|
|
|
|
|
|
FieldByName(fld_PresupuestosClienteDESCUENTO).OnChange := DESCUENTOOnChange;
|
|
|
|
|
|
FieldByName(fld_PresupuestosClienteIVA).OnChange := IVAOnChange;
|
2007-10-26 18:19:55 +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
|
2007-11-05 17:49:11 +00:00
|
|
|
|
Add(SITUACION_PRESUPUESTO_PENDIENTE);
|
|
|
|
|
|
Add(SITUACION_PRESUPUESTO_ACEPTADO);
|
|
|
|
|
|
Add(SITUACION_PRESUPUESTO_ANULADO);
|
2007-10-26 18:19:55 +00:00
|
|
|
|
end;
|
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
|
|
procedure TBizPresupuestoCliente.DESCUENTOOnChange(Sender: TDACustomField);
|
|
|
|
|
|
begin
|
|
|
|
|
|
CalcularImporteTotal;
|
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
|
|
destructor TBizPresupuestoCliente.Destroy;
|
|
|
|
|
|
begin
|
|
|
|
|
|
FCliente := NIL;
|
|
|
|
|
|
FDetalles := NIL;
|
|
|
|
|
|
FDetallesLink.Free;
|
|
|
|
|
|
|
|
|
|
|
|
FSeleccionableInterface := NIL;
|
|
|
|
|
|
inherited;
|
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
|
|
function TBizPresupuestoCliente.EsNuevo: Boolean;
|
|
|
|
|
|
begin
|
|
|
|
|
|
Result := (ID < 0);
|
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
|
|
function TBizPresupuestoCliente.GetCliente: IBizCliente;
|
|
|
|
|
|
begin
|
|
|
|
|
|
Result := FCliente;
|
|
|
|
|
|
end;
|
|
|
|
|
|
|
2008-11-11 18:56:40 +00:00
|
|
|
|
procedure TBizPresupuestoCliente.IMPORTE_BONIFICACIONOnChange(Sender: TDACustomField);
|
|
|
|
|
|
begin
|
|
|
|
|
|
CalcularImporteTotal;
|
|
|
|
|
|
end;
|
|
|
|
|
|
|
2007-10-26 18:19:55 +00:00
|
|
|
|
procedure TBizPresupuestoCliente.IMPORTE_NETOOnChange(Sender: TDACustomField);
|
|
|
|
|
|
begin
|
|
|
|
|
|
CalcularImporteTotal;
|
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
|
|
procedure TBizPresupuestoCliente.IMPORTE_PORTEOnChange(Sender: TDACustomField);
|
|
|
|
|
|
begin
|
|
|
|
|
|
CalcularImporteTotal;
|
|
|
|
|
|
end;
|
|
|
|
|
|
|
2007-11-05 17:49:11 +00:00
|
|
|
|
procedure TBizPresupuestoCliente.IniciarValoresPresupuestoNuevo;
|
2007-10-26 18:19:55 +00:00
|
|
|
|
begin
|
2007-11-18 15:07:51 +00:00
|
|
|
|
ID_EMPRESA := AppFactuGES.EmpresaActiva.ID;
|
|
|
|
|
|
USUARIO := AppFactuGES.UsuarioActivo.UserName;
|
2007-11-05 17:49:11 +00:00
|
|
|
|
FECHA_PRESUPUESTO := DateOf(Date);
|
2007-10-26 18:19:55 +00:00
|
|
|
|
INCIDENCIAS_ACTIVAS := 0;
|
2014-02-18 22:41:52 +00:00
|
|
|
|
CERTIFICADO_ISO := 1;
|
2007-10-26 18:19:55 +00:00
|
|
|
|
// INCIDENCIAS := NIL;
|
|
|
|
|
|
REFERENCIA := '';
|
2007-11-05 17:49:11 +00:00
|
|
|
|
SITUACION := SITUACION_PRESUPUESTO_PENDIENTE;
|
2007-10-26 18:19:55 +00:00
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
|
|
procedure TBizPresupuestoCliente.IVAOnChange(Sender: TDACustomField);
|
|
|
|
|
|
begin
|
|
|
|
|
|
CalcularImporteTotal;
|
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
|
|
function TBizPresupuestoCliente.GetDetalles: IBizDetallesPresupuestoCliente;
|
|
|
|
|
|
begin
|
|
|
|
|
|
Result := FDetalles;
|
|
|
|
|
|
end;
|
|
|
|
|
|
|
2007-11-12 19:36:34 +00:00
|
|
|
|
function TBizPresupuestoCliente.GetSITUACIONValue: String;
|
|
|
|
|
|
begin
|
|
|
|
|
|
result := Trim(DataTable.Fields[idx_PresupuestosClienteSITUACION].AsString);
|
|
|
|
|
|
end;
|
|
|
|
|
|
|
2007-10-26 18:19:55 +00:00
|
|
|
|
procedure TBizPresupuestoCliente.OnNewRecord(Sender: TDADataTable);
|
|
|
|
|
|
begin
|
|
|
|
|
|
inherited;
|
2007-11-05 17:49:11 +00:00
|
|
|
|
// ID := GetRecNo; // -1, -2, -3...
|
|
|
|
|
|
IniciarValoresPresupuestoNuevo;
|
2007-10-26 18:19:55 +00:00
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
|
|
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:35:45 +00:00
|
|
|
|
if FCliente.ID_FORMA_PAGO > 0 then
|
|
|
|
|
|
ID_FORMA_PAGO := FCliente.ID_FORMA_PAGO;
|
2008-08-20 10:18:16 +00:00
|
|
|
|
DESCUENTO := FCliente.DESCUENTO;
|
2007-10-26 18:19:55 +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;
|
|
|
|
|
|
|
2007-11-05 17:49:11 +00:00
|
|
|
|
procedure TBizPresupuestoCliente.SetFECHA_PRESUPUESTOValue(const aValue: TDateTime);
|
2007-10-26 18:19:55 +00:00
|
|
|
|
begin
|
|
|
|
|
|
if EsFechaVacia(aValue) then
|
2007-11-05 17:49:11 +00:00
|
|
|
|
SetFieldNull(DataTable, fld_PresupuestosClienteFECHA_PRESUPUESTO)
|
2007-10-26 18:19:55 +00:00
|
|
|
|
else
|
|
|
|
|
|
inherited;
|
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
|
|
procedure TBizPresupuestoCliente.SetID_FORMA_PAGOValue(const aValue: Integer);
|
|
|
|
|
|
begin
|
|
|
|
|
|
if (aValue = 0) then
|
2007-11-05 17:49:11 +00:00
|
|
|
|
SetFieldNull(DataTable, fld_PresupuestosClienteID_FORMA_PAGO)
|
2007-10-26 18:19:55 +00:00
|
|
|
|
else
|
|
|
|
|
|
inherited;
|
|
|
|
|
|
end;
|
|
|
|
|
|
{
|
|
|
|
|
|
procedure TBizPresupuestoCliente.SetINCIDENCIASValue(const aValue: IROStrings);
|
|
|
|
|
|
begin
|
|
|
|
|
|
if not Assigned(aValue) then
|
2007-11-05 17:49:11 +00:00
|
|
|
|
SetFieldNull(DataTable, fld_PresupuestosClienteINCIDENCIAS)
|
2007-10-26 18:19:55 +00:00
|
|
|
|
else
|
|
|
|
|
|
inherited;
|
|
|
|
|
|
end;
|
|
|
|
|
|
}
|
|
|
|
|
|
function TBizPresupuestoCliente._GetCliente: IBizCliente;
|
|
|
|
|
|
begin
|
|
|
|
|
|
Result := FCliente;
|
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
|
|
procedure TBizPresupuestoCliente._SetCliente(AValue: IBizCliente);
|
|
|
|
|
|
begin
|
|
|
|
|
|
FCliente := AValue;
|
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
|
|
initialization
|
2007-11-05 17:49:11 +00:00
|
|
|
|
RegisterDataTableRules(BIZ_CLIENT_PRESUPUESTO_CLIENTE, TBizPresupuestoCliente);
|
|
|
|
|
|
|
2007-10-26 18:19:55 +00:00
|
|
|
|
finalization
|
|
|
|
|
|
|
|
|
|
|
|
end.
|
|
|
|
|
|
|