git-svn-id: https://192.168.0.254/svn/Proyectos.ConstruccionesCNJ_FactuGES/trunk@4 6cb6b671-b4a0-dd4c-8bdc-3006503d97e9
229 lines
5.9 KiB
ObjectPascal
229 lines
5.9 KiB
ObjectPascal
unit uBizFacturasCliente;
|
|
|
|
interface
|
|
|
|
uses
|
|
uDAInterfaces, uDADataTable, schFacturasClienteClient_Intf,
|
|
uBizContactos, uBizDetallesFacturaCliente, Classes;
|
|
|
|
const
|
|
BIZ_CLIENT_FACTURA_CLIENTE = 'Client.FacturaCliente';
|
|
|
|
SITUACION_PENDIENTE = 'Pendiente';
|
|
SITUACION_PAGADO = 'Pagado';
|
|
|
|
DIAS_VENCIMIENTO = 30;
|
|
type
|
|
IBizFacturaCliente = interface(IFacturasCliente)
|
|
['{36145458-DB0B-4A53-A17C-0B20B473D831}']
|
|
|
|
procedure SetCliente(AValue : IBizCliente);
|
|
function GetCliente : IBizCliente;
|
|
property Cliente : IBizCliente read GetCliente write SetCliente;
|
|
|
|
function GetDetalles: IBizDetallesFacturaCliente;
|
|
procedure SetDetalles(Value: IBizDetallesFacturaCliente);
|
|
property Detalles: IBizDetallesFacturaCliente read GetDetalles write SetDetalles;
|
|
|
|
function EsNuevo : Boolean;
|
|
procedure CalcularImporteTotal;
|
|
function DarListaSituaciones: TStringList;
|
|
end;
|
|
|
|
TBizFacturaCliente = class(TFacturasClienteDataTableRules, IBizFacturaCliente)
|
|
private
|
|
procedure CalcularDescuento;
|
|
procedure CalcularIVA;
|
|
protected
|
|
FCliente : IBizCliente;
|
|
FDetalles : IBizDetallesFacturaCliente;
|
|
FDetallesLink : TDADataSource;
|
|
|
|
procedure SetCliente(AValue : IBizCliente);
|
|
function GetCliente : IBizCliente;
|
|
|
|
function GetDetalles: IBizDetallesFacturaCliente;
|
|
procedure SetDetalles(Value: IBizDetallesFacturaCliente);
|
|
|
|
procedure SetBASE_IMPONIBLEValue(const aValue: Float); override;
|
|
procedure SetDESCUENTOValue(const aValue: Double); override;
|
|
procedure SetIVAValue(const aValue: Double); override;
|
|
procedure SetFECHA_PAGADOValue(const aValue: TDateTime); override;
|
|
procedure OnNewRecord(Sender: TDADataTable); override;
|
|
procedure OnCalcFields(Sender: TDADataTable); override;
|
|
public
|
|
function EsNuevo : Boolean;
|
|
procedure IniciarValoresFacturaNueva;
|
|
procedure CalcularImporteTotal;
|
|
function DarListaSituaciones: TStringList;
|
|
|
|
property Cliente : IBizCliente read GetCliente write SetCliente;
|
|
property Detalles: IBizDetallesFacturaCliente read GetDetalles write SetDetalles;
|
|
|
|
constructor Create(aDataTable: TDADataTable); override;
|
|
destructor Destroy; override;
|
|
end;
|
|
|
|
implementation
|
|
|
|
uses
|
|
SysUtils, uDataTableUtils, DB, uDateUtils, DateUtils, uDataModuleUsuarios,
|
|
Variants, cxDateUtils;
|
|
|
|
{ TBizFacturaCliente }
|
|
|
|
function TBizFacturaCliente.EsNuevo: Boolean;
|
|
begin
|
|
Result := (ID < 0);
|
|
end;
|
|
|
|
|
|
procedure TBizFacturaCliente.CalcularDescuento;
|
|
begin
|
|
if not Self.DataTable.Editing then Edit;
|
|
IMPORTE_DESCUENTO := (DESCUENTO / 100) * BASE_IMPONIBLE;
|
|
end;
|
|
|
|
procedure TBizFacturaCliente.CalcularImporteTotal;
|
|
begin
|
|
CalcularDescuento; //Importante orden
|
|
CalcularIVA;
|
|
|
|
if not Self.DataTable.Editing then Edit;
|
|
IMPORTE_TOTAL := BASE_IMPONIBLE - IMPORTE_DESCUENTO + IMPORTE_IVA;
|
|
end;
|
|
|
|
procedure TBizFacturaCliente.CalcularIVA;
|
|
begin
|
|
if not Self.DataTable.Editing then Edit;
|
|
IMPORTE_IVA := (IVA / 100) * (BASE_IMPONIBLE - IMPORTE_DESCUENTO);
|
|
end;
|
|
|
|
constructor TBizFacturaCliente.Create(aDataTable: TDADataTable);
|
|
begin
|
|
inherited;
|
|
FCliente := Nil;
|
|
FDetallesLink := TDADataSource.Create(NIL);
|
|
FDetallesLink.DataTable := aDataTable;
|
|
end;
|
|
|
|
function TBizFacturaCliente.DarListaSituaciones: TStringList;
|
|
begin
|
|
Result := TStringList.Create;
|
|
with Result do
|
|
begin
|
|
Add(SITUACION_PENDIENTE);
|
|
Add(SITUACION_PAGADO);
|
|
end;
|
|
end;
|
|
|
|
destructor TBizFacturaCliente.Destroy;
|
|
begin
|
|
FCliente := NIL;
|
|
FDetalles := NIL;
|
|
FDetallesLink.Free;
|
|
inherited;
|
|
end;
|
|
|
|
function TBizFacturaCliente.GetCliente: IBizCliente;
|
|
begin
|
|
Result := FCliente;
|
|
end;
|
|
|
|
function TBizFacturaCliente.GetDetalles: IBizDetallesFacturaCliente;
|
|
begin
|
|
Result := FDetalles;
|
|
end;
|
|
|
|
procedure TBizFacturaCliente.IniciarValoresFacturaNueva;
|
|
begin
|
|
ID_EMPRESA := dmUsuarios.IDEmpresaActual;
|
|
USUARIO := dmUsuarios.LoginInfo.Usuario;
|
|
FECHA_FACTURA := DateOf(Now);
|
|
VENCIMIENTO := DIAS_VENCIMIENTO;
|
|
SITUACION := SITUACION_PENDIENTE;
|
|
ID_CLIENTE := ID_NULO;
|
|
FECHA_PAGADO := 0;
|
|
IVA := dmUsuarios.EmpresaActual.IVA;
|
|
end;
|
|
|
|
procedure TBizFacturaCliente.OnCalcFields(Sender: TDADataTable);
|
|
begin
|
|
inherited;
|
|
FECHA_VENCIMIENTO := IncDay(FECHA_FACTURA, VENCIMIENTO);
|
|
end;
|
|
|
|
procedure TBizFacturaCliente.OnNewRecord(Sender: TDADataTable);
|
|
begin
|
|
inherited;
|
|
ID := GetRecNo; // -1, -2, -3...
|
|
IniciarValoresFacturaNueva;
|
|
end;
|
|
|
|
procedure TBizFacturaCliente.SetBASE_IMPONIBLEValue(const aValue: Float);
|
|
begin
|
|
inherited;
|
|
CalcularImporteTotal;
|
|
end;
|
|
|
|
procedure TBizFacturaCliente.SetCliente(AValue: IBizCliente);
|
|
var
|
|
bEnEdicion : Boolean;
|
|
begin
|
|
FCliente := AValue;
|
|
|
|
bEnEdicion := (DataTable.State in dsEditModes);
|
|
if not bEnEdicion then
|
|
Edit;
|
|
if Assigned(FCliente) then
|
|
begin
|
|
if not FCliente.DataTable.Active then
|
|
FCliente.DataTable.Active := True;
|
|
|
|
ID_CLIENTE := FCliente.ID;
|
|
NOMBRE := FCliente.NOMBRE;
|
|
NIF_CIF := FCliente.NIF_CIF;
|
|
CALLE := FCliente.CALLE;
|
|
CODIGO_POSTAL := FCliente.CODIGO_POSTAL;
|
|
PROVINCIA := FCliente.PROVINCIA;
|
|
POBLACION := FCliente.POBLACION;
|
|
Post;
|
|
if bEnEdicion then
|
|
Edit;
|
|
end
|
|
end;
|
|
|
|
procedure TBizFacturaCliente.SetDESCUENTOValue(const aValue: Double);
|
|
begin
|
|
inherited;
|
|
CalcularImporteTotal;
|
|
end;
|
|
|
|
procedure TBizFacturaCliente.SetDetalles(Value: IBizDetallesFacturaCliente);
|
|
begin
|
|
FDetalles := Value;
|
|
EnlazarMaestroDetalle(FDetallesLink, FDetalles);
|
|
end;
|
|
|
|
procedure TBizFacturaCliente.SetFECHA_PAGADOValue(const aValue: TDateTime);
|
|
begin
|
|
if EsFechaVacia(aValue) then
|
|
DataTable.Fields[idx_FacturasClienteFECHA_PAGADO].AsVariant := NULL
|
|
else
|
|
inherited;
|
|
end;
|
|
|
|
procedure TBizFacturaCliente.SetIVAValue(const aValue: Double);
|
|
begin
|
|
inherited;
|
|
CalcularImporteTotal;
|
|
end;
|
|
|
|
initialization
|
|
RegisterDataTableRules(BIZ_CLIENT_FACTURA_CLIENTE, TBizFacturaCliente);
|
|
|
|
finalization
|
|
|
|
end.
|
|
|