228 lines
6.6 KiB
ObjectPascal
228 lines
6.6 KiB
ObjectPascal
|
|
unit uBizRecibosCliente;
|
|||
|
|
|
|||
|
|
interface
|
|||
|
|
|
|||
|
|
uses
|
|||
|
|
uDAInterfaces, uDADataTable, Classes, uBizContacto, DB,
|
|||
|
|
uDBSelectionList, uExceptions, uBizInformesBase,
|
|||
|
|
schRecibosClienteClient_Intf;
|
|||
|
|
|
|||
|
|
const
|
|||
|
|
BIZ_RECIBOSCLIENTE = 'Client.RecibosCliente';
|
|||
|
|
|
|||
|
|
type
|
|||
|
|
IBizRecibosCliente = interface(IRecibosCliente)
|
|||
|
|
['{362DC7FF-2017-43B9-8F2C-A29C4F550C0B}']
|
|||
|
|
function GetCliente: IBizContacto;
|
|||
|
|
procedure SetCliente(Value: IBizContacto);
|
|||
|
|
property Cliente: IBizContacto read GetCliente write SetCliente;
|
|||
|
|
|
|||
|
|
procedure Show;
|
|||
|
|
procedure CopyFrom(AReciboCliente : IBizRecibosCliente);
|
|||
|
|
end;
|
|||
|
|
|
|||
|
|
TBizRecibosCliente = class(TRecibosClienteDataTableRules, IBizRecibosCliente,
|
|||
|
|
ISelectedRowList, IApplyUpdateFailedException,
|
|||
|
|
IBizInformesAware)
|
|||
|
|
private
|
|||
|
|
FCliente : IBizContacto;
|
|||
|
|
FSelectedRows : TSelectedRowList;
|
|||
|
|
|
|||
|
|
protected
|
|||
|
|
function GetCliente: IBizContacto;
|
|||
|
|
procedure SetCliente(Value: IBizContacto);
|
|||
|
|
|
|||
|
|
procedure OnNewRecord(Sender: TDADataTable); override;
|
|||
|
|
procedure ShowApplyUpdateFailed (const Error: EDAApplyUpdateFailed);
|
|||
|
|
function GetSelectedRows : TSelectedRowList;
|
|||
|
|
procedure OnPostError(DataTable: TDADataTable; Error: EDatabaseError; var Action: TDataAction); override;
|
|||
|
|
procedure BeforeApplyUpdates(Sender : TDADataTable; const Delta : IDADelta);
|
|||
|
|
|
|||
|
|
public
|
|||
|
|
property Cliente: IBizContacto read GetCliente write SetCliente;
|
|||
|
|
constructor Create(aDataTable: TDADataTable); override;
|
|||
|
|
destructor Destroy; override;
|
|||
|
|
procedure Show; virtual;
|
|||
|
|
procedure Preview;
|
|||
|
|
procedure Print;
|
|||
|
|
property SelectedRows : TSelectedRowList read GetSelectedRows;
|
|||
|
|
procedure CopyFrom(AReciboCliente : IBizRecibosCliente);
|
|||
|
|
end;
|
|||
|
|
|
|||
|
|
procedure ValidarReciboCliente (const AReciboCliente : IBizRecibosCliente);
|
|||
|
|
|
|||
|
|
|
|||
|
|
implementation
|
|||
|
|
|
|||
|
|
uses
|
|||
|
|
Windows, Dialogs, uDACDSDataTable, SysUtils, uEditorUtils, Variants, Math,
|
|||
|
|
uDataModuleContactos, Controls, Forms, uDataModuleBase, uDataTableUtils,
|
|||
|
|
uDataModuleRecibosCliente, LiteralesRecibosCliente;
|
|||
|
|
|
|||
|
|
procedure ValidarReciboCliente (const AReciboCliente : IBizRecibosCliente);
|
|||
|
|
begin
|
|||
|
|
if (FloatToStr(AReciboCliente.FECHARECIBO) = '0') then
|
|||
|
|
raise Exception.Create(msgLitFechaObligatorio);
|
|||
|
|
|
|||
|
|
if not Assigned(AReciboCliente.Cliente) or
|
|||
|
|
(AReciboCliente.Cliente.DataTable.IsEmpty) then
|
|||
|
|
raise Exception.Create(msgLitClienteObligatorio);
|
|||
|
|
end;
|
|||
|
|
|
|||
|
|
constructor TBizRecibosCliente.Create(aDataTable: TDADataTable);
|
|||
|
|
begin
|
|||
|
|
inherited;
|
|||
|
|
FCliente := NIL;
|
|||
|
|
FSelectedRows := TSelectedRowList.Create(aDataTable);
|
|||
|
|
aDataTable.OnBeforeApplyUpdates := BeforeApplyUpdates;
|
|||
|
|
end;
|
|||
|
|
|
|||
|
|
destructor TBizRecibosCliente.Destroy;
|
|||
|
|
begin
|
|||
|
|
FCliente := NIL;
|
|||
|
|
FSelectedRows.Free;
|
|||
|
|
inherited;
|
|||
|
|
end;
|
|||
|
|
|
|||
|
|
function TBizRecibosCliente.GetCliente: IBizContacto;
|
|||
|
|
begin
|
|||
|
|
if not Assigned(FCliente) or
|
|||
|
|
((CODIGOCONTACTO <> FCliente.Codigo) and
|
|||
|
|
not (FCliente.DataTable.State in dsEditModes)) then
|
|||
|
|
begin
|
|||
|
|
FCliente := dmContactos.GetContacto(CODIGOCONTACTO);
|
|||
|
|
if not FCliente.DataTable.Active then
|
|||
|
|
FCliente.DataTable.Active := True;
|
|||
|
|
if not FCliente.DataTable.IsEmpty then // Est<73> vac<61>o si la factura es nueva y no tiene cliente
|
|||
|
|
begin
|
|||
|
|
FCliente.Edit;
|
|||
|
|
FCliente.NOMBRE := NOMBRE;
|
|||
|
|
FCliente.NIFCIF := NIFCIF;
|
|||
|
|
FCliente.CALLE := CALLE;
|
|||
|
|
FCliente.CODIGOPOSTAL := CODIGOPOSTAL;
|
|||
|
|
FCliente.PROVINCIA := PROVINCIA;
|
|||
|
|
FCliente.POBLACION := POBLACION;
|
|||
|
|
FCliente.Post;
|
|||
|
|
end;
|
|||
|
|
end;
|
|||
|
|
Result := FCliente;
|
|||
|
|
end;
|
|||
|
|
|
|||
|
|
procedure TBizRecibosCliente.CopyFrom(AReciboCliente : IBizRecibosCliente);
|
|||
|
|
var
|
|||
|
|
ACursor: TCursor;
|
|||
|
|
begin
|
|||
|
|
if not (State in dsEditModes) then
|
|||
|
|
Edit;
|
|||
|
|
|
|||
|
|
ACursor := Screen.Cursor;
|
|||
|
|
Screen.Cursor := crHourGlass;
|
|||
|
|
Application.ProcessMessages;
|
|||
|
|
try
|
|||
|
|
CODIGO := dmRecibosCliente.GetNextAutoinc;
|
|||
|
|
FECHAALTA := dmBase.Fecha;
|
|||
|
|
USUARIO := dmBase.Usuario;
|
|||
|
|
FECHARECIBO := AReciboCliente.FECHARECIBO;
|
|||
|
|
IMPORTE := AReciboCliente.IMPORTE;
|
|||
|
|
TEXTO := AReciboCliente.TEXTO;
|
|||
|
|
CODIGOCONTACTO := AReciboCliente.CODIGOCONTACTO;
|
|||
|
|
Cliente := AReciboCliente.Cliente;
|
|||
|
|
|
|||
|
|
if not AReciboCliente.DataTable.FieldByName(fld_RecibosClienteCODIGOOBRA).IsNull then
|
|||
|
|
CODIGOOBRA := AReciboCliente.CODIGOOBRA;
|
|||
|
|
Post;
|
|||
|
|
MessageBox(0, 'Se ha duplicado correctamente el recibo elegida.', 'Recibo duplicado', MB_ICONWARNING or MB_OK);
|
|||
|
|
finally
|
|||
|
|
Screen.Cursor := ACursor;
|
|||
|
|
end;
|
|||
|
|
end;
|
|||
|
|
|
|||
|
|
procedure TBizRecibosCliente.OnNewRecord(Sender: TDADataTable);
|
|||
|
|
begin
|
|||
|
|
inherited;
|
|||
|
|
USUARIO := dmBase.Usuario;
|
|||
|
|
FECHAALTA := dmBase.Fecha;
|
|||
|
|
FECHARECIBO := dmBase.Fecha;
|
|||
|
|
CODIGO := dmRecibosCliente.GetNextAutoinc;
|
|||
|
|
IMPORTE := 0;
|
|||
|
|
end;
|
|||
|
|
|
|||
|
|
procedure TBizRecibosCliente.Preview;
|
|||
|
|
begin
|
|||
|
|
dmRecibosCliente.Preview(Self.CODIGO);
|
|||
|
|
end;
|
|||
|
|
|
|||
|
|
procedure TBizRecibosCliente.SetCliente(Value: IBizContacto);
|
|||
|
|
var
|
|||
|
|
bEnEdicion : Boolean;
|
|||
|
|
begin
|
|||
|
|
bEnEdicion := (DataTable.State in dsEditModes);
|
|||
|
|
if not bEnEdicion then
|
|||
|
|
Edit;
|
|||
|
|
FCliente := Value;
|
|||
|
|
if Assigned(FCliente) then
|
|||
|
|
begin
|
|||
|
|
CODIGOCONTACTO := FCliente.CODIGO;
|
|||
|
|
NOMBRE := FCliente.NOMBRE;
|
|||
|
|
NIFCIF := FCliente.NIFCIF;
|
|||
|
|
CALLE := FCliente.CALLE;
|
|||
|
|
CODIGOPOSTAL := FCliente.CODIGOPOSTAL;
|
|||
|
|
PROVINCIA := FCliente.PROVINCIA;
|
|||
|
|
POBLACION := FCliente.POBLACION;
|
|||
|
|
if not bEnEdicion then
|
|||
|
|
Post;
|
|||
|
|
end
|
|||
|
|
end;
|
|||
|
|
|
|||
|
|
procedure TBizRecibosCliente.Show;
|
|||
|
|
begin
|
|||
|
|
ShowEditor(IBizRecibosCliente, Self, etItem);
|
|||
|
|
end;
|
|||
|
|
|
|||
|
|
function TBizRecibosCliente.GetSelectedRows: TSelectedRowList;
|
|||
|
|
begin
|
|||
|
|
Result := FSelectedRows;
|
|||
|
|
end;
|
|||
|
|
|
|||
|
|
procedure TBizRecibosCliente.ShowApplyUpdateFailed(const Error: EDAApplyUpdateFailed);
|
|||
|
|
begin
|
|||
|
|
if (Pos(AUF_FKVIOLATION, Error.Message) > 0) then
|
|||
|
|
MessageBox(0, PChar(msgLitErrorBorrar), 'Atenci<63>n', MB_ICONWARNING or MB_OK);
|
|||
|
|
end;
|
|||
|
|
|
|||
|
|
procedure TBizRecibosCliente.Print;
|
|||
|
|
begin
|
|||
|
|
dmRecibosCliente.Print(Self.CODIGO);
|
|||
|
|
end;
|
|||
|
|
|
|||
|
|
procedure TBizRecibosCliente.OnPostError(DataTable: TDADataTable; Error: EDatabaseError; var Action: TDataAction);
|
|||
|
|
begin
|
|||
|
|
inherited;
|
|||
|
|
Action := daAbort;
|
|||
|
|
if (Pos('Nombre', Error.Message) > 0) then
|
|||
|
|
MessageBox(0, PChar(msgLitClienteObligatorio), 'Atenci<63>n', MB_ICONWARNING or MB_OK)
|
|||
|
|
else if (Pos('Fecha', Error.Message) > 0) then
|
|||
|
|
MessageBox(0, PChar(msgLitFechaObligatorio), 'Atenci<63>n', MB_ICONWARNING or MB_OK)
|
|||
|
|
else
|
|||
|
|
raise Error;
|
|||
|
|
end;
|
|||
|
|
|
|||
|
|
procedure TBizRecibosCliente.BeforeApplyUpdates(Sender: TDADataTable;
|
|||
|
|
const Delta: IDADelta);
|
|||
|
|
var
|
|||
|
|
i : integer;
|
|||
|
|
begin
|
|||
|
|
for i := 0 to Delta.Count - 1 do
|
|||
|
|
case Delta.Changes[i].ChangeType of
|
|||
|
|
ctInsert, ctUpdate : ValidarReciboCliente(Self);
|
|||
|
|
//ctDelete :
|
|||
|
|
end;
|
|||
|
|
end;
|
|||
|
|
|
|||
|
|
initialization
|
|||
|
|
RegisterDataTableRules(BIZ_RECIBOSCLIENTE, TBizRecibosCliente);
|
|||
|
|
|
|||
|
|
finalization
|
|||
|
|
|
|||
|
|
end.
|