218 lines
7.2 KiB
ObjectPascal
218 lines
7.2 KiB
ObjectPascal
|
|
{
|
|||
|
|
===============================================================================
|
|||
|
|
Copyright (<EFBFBD>) 2007. Rodax Software.
|
|||
|
|
===============================================================================
|
|||
|
|
Los contenidos de este fichero son propiedad de Rodax Software titular del
|
|||
|
|
copyright. Este fichero s<EFBFBD>lo podr<EFBFBD> ser copiado, distribuido y utilizado,
|
|||
|
|
en su totalidad o en parte, con el permiso escrito de Rodax Software, o de
|
|||
|
|
acuerdo con los t<EFBFBD>rminos y condiciones establecidas en el acuerdo/contrato
|
|||
|
|
bajo el que se suministra.
|
|||
|
|
-----------------------------------------------------------------------------
|
|||
|
|
Web: www.rodax-software.com
|
|||
|
|
===============================================================================
|
|||
|
|
Fecha primera versi<EFBFBD>n:
|
|||
|
|
Versi<EFBFBD>n actual: 1.0.0
|
|||
|
|
Fecha versi<EFBFBD>n actual:
|
|||
|
|
===============================================================================
|
|||
|
|
Modificaciones:
|
|||
|
|
|
|||
|
|
Fecha Comentarios
|
|||
|
|
---------------------------------------------------------------------------
|
|||
|
|
===============================================================================
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
unit uPagosClienteController;
|
|||
|
|
|
|||
|
|
interface
|
|||
|
|
|
|||
|
|
uses
|
|||
|
|
Classes, SysUtils, uDADataTable, uControllerBase, uIDataModuleRecibosCliente,
|
|||
|
|
uBizPagosCliente;
|
|||
|
|
|
|||
|
|
type
|
|||
|
|
IPagosClienteController = interface(ISujeto)
|
|||
|
|
['{1864471E-74FA-4E96-BA8D-21357DA38B0F}']
|
|||
|
|
function Anadir(APagosCliente: IBizPagosCliente; Const Fecha: String = ''): Boolean;
|
|||
|
|
procedure Modificar(APagosCliente: IBizPagosCliente; Const Fecha: String);
|
|||
|
|
function Eliminar(APagoCliente : IBizPagosCliente): Boolean;
|
|||
|
|
function EliminarTodo(APagossCliente : IBizPagosCliente): Boolean;
|
|||
|
|
procedure AsignarID(APagosCliente: IBizPagosCliente; IDCabecera: Integer; AEsNuevo:Boolean);
|
|||
|
|
end;
|
|||
|
|
|
|||
|
|
TPagosClienteController = class(TSujeto, IPagosClienteController)
|
|||
|
|
protected
|
|||
|
|
FDataModule : IDataModuleRecibosCliente;
|
|||
|
|
|
|||
|
|
procedure AsignarDataModule;
|
|||
|
|
procedure AsignarDatos(APagosCliente: IBizPagosCliente; IDCabecera: Integer);
|
|||
|
|
|
|||
|
|
public
|
|||
|
|
constructor Create; virtual;
|
|||
|
|
destructor Destroy; override;
|
|||
|
|
procedure AsignarID(APagosCliente: IBizPagosCliente; IDCabecera: Integer; AEsNuevo:Boolean);
|
|||
|
|
function Anadir(APagosCliente: IBizPagosCliente; Const Fecha: String = ''): Boolean;
|
|||
|
|
procedure Modificar(APagosCliente: IBizPagosCliente; Const Fecha: String);
|
|||
|
|
function Eliminar(APagoCliente : IBizPagosCliente): Boolean;
|
|||
|
|
function EliminarTodo(APagosCliente : IBizPagosCliente): Boolean;
|
|||
|
|
end;
|
|||
|
|
|
|||
|
|
implementation
|
|||
|
|
|
|||
|
|
uses
|
|||
|
|
cxControls, DB, uEditorRegistryUtils,Dialogs,
|
|||
|
|
uDAInterfaces, uDataTableUtils, uDataModuleUsuarios,
|
|||
|
|
uDateUtils, uROTypes, DateUtils, Controls, Windows, Variants,
|
|||
|
|
schRecibosClienteClient_Intf, uDataModuleRecibosCliente;
|
|||
|
|
|
|||
|
|
{ TPagosClienteController }
|
|||
|
|
|
|||
|
|
function TPagosClienteController.Anadir(APagosCliente: IBizPagosCliente; Const Fecha: String = ''): Boolean;
|
|||
|
|
{ Si el pago introducido es un pago y no una devoluci<EFBFBD>n devolvemos true en caso de ser
|
|||
|
|
una devoluci<EFBFBD>n devolvemos false}
|
|||
|
|
begin
|
|||
|
|
APagosCliente.Append;
|
|||
|
|
if Length(Fecha) = 0 then
|
|||
|
|
APagosCliente.FECHA_PAGO := Date
|
|||
|
|
else
|
|||
|
|
APagosCliente.FECHA_PAGO := StrToDate(Fecha);
|
|||
|
|
|
|||
|
|
if (APagosCliente.DataTable.RecordCount = 0)
|
|||
|
|
or ((APagosCliente.DataTable.RecordCount mod 2) = 0) then
|
|||
|
|
APagosCliente.TIPO := CTE_PAGO
|
|||
|
|
else
|
|||
|
|
APagosCliente.TIPO := CTE_DEVOLUCION;
|
|||
|
|
|
|||
|
|
Result := (APagosCliente.TIPO = CTE_PAGO);
|
|||
|
|
APagosCliente.Post;
|
|||
|
|
end;
|
|||
|
|
|
|||
|
|
procedure TPagosClienteController.AsignarDataModule;
|
|||
|
|
begin
|
|||
|
|
FDataModule := TDataModuleRecibosCliente.Create(Nil);
|
|||
|
|
end;
|
|||
|
|
|
|||
|
|
procedure TPagosClienteController.AsignarDatos(APagosCliente: IBizPagosCliente; IDCabecera: Integer);
|
|||
|
|
begin
|
|||
|
|
inherited;
|
|||
|
|
APagosCliente.Edit;
|
|||
|
|
APagosCliente.ID := FDataModule.GetNextID(APagosCliente.DataTable.LogicalName);
|
|||
|
|
APagosCliente.ID_RECIBO := IDCabecera;
|
|||
|
|
APagosCliente.Post
|
|||
|
|
end;
|
|||
|
|
|
|||
|
|
procedure TPagosClienteController.AsignarID(APagosCliente: IBizPagosCliente; IDCabecera: Integer; AEsNuevo:Boolean);
|
|||
|
|
begin
|
|||
|
|
with APagosCliente do
|
|||
|
|
begin
|
|||
|
|
DataTable.DisableControls;
|
|||
|
|
try
|
|||
|
|
begin
|
|||
|
|
if not DataTable.Active then
|
|||
|
|
DataTable.Active := True;
|
|||
|
|
|
|||
|
|
{ <EFBFBD><EFBFBD><EFBFBD><EFBFBD> OJO !!!!
|
|||
|
|
Para asignar el ID en los detalles hay
|
|||
|
|
que tener en cuenta una cosa:
|
|||
|
|
Si se cambia el ID, ese detalle ya no
|
|||
|
|
pertenece a esa cabecera porque ya no se
|
|||
|
|
cumple la condici<EFBFBD>n de la relacion:
|
|||
|
|
Master.ID = Detail.ID_PRESUPUESTO.
|
|||
|
|
|
|||
|
|
Por esa raz<EFBFBD>n no sirve hacer un recorrido
|
|||
|
|
desde el principio hasta el final porque
|
|||
|
|
las detalles van desapareciendo seg<EFBFBD>n asignamos
|
|||
|
|
el valor al campo ID y nos mueve aleatoriamente
|
|||
|
|
la posici<EFBFBD>n del registro actual.
|
|||
|
|
|
|||
|
|
Es mejor hacer un bucle sencillo hasta que
|
|||
|
|
"se gasten" todos los detalles. Cuando el
|
|||
|
|
RecordCount llegue a 0 quiere decir que hemos
|
|||
|
|
tratado todos los detalles.
|
|||
|
|
|
|||
|
|
El bucle cambia en el caso de ser llamada esta funcion desde modificar
|
|||
|
|
un presupuesto ya que en ese caso si que hay que hacer un recorrido
|
|||
|
|
total de las tuplas de detalle.
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
if AEsNuevo then
|
|||
|
|
begin
|
|||
|
|
while RecordCount > 0 do
|
|||
|
|
begin
|
|||
|
|
DataTable.First;
|
|||
|
|
AsignarDatos(APagosCliente, IDCabecera);
|
|||
|
|
end
|
|||
|
|
end
|
|||
|
|
else
|
|||
|
|
begin
|
|||
|
|
DataTable.First;
|
|||
|
|
while not DataTable.EOF do
|
|||
|
|
begin
|
|||
|
|
if DataTable.FieldByName('ID').AsInteger < 0 then
|
|||
|
|
AsignarDatos(APagosCliente, IDCabecera);
|
|||
|
|
DataTable.Next
|
|||
|
|
end;
|
|||
|
|
end;
|
|||
|
|
end;
|
|||
|
|
finally
|
|||
|
|
DataTable.EnableControls;
|
|||
|
|
end;
|
|||
|
|
end;
|
|||
|
|
end;
|
|||
|
|
|
|||
|
|
constructor TPagosClienteController.Create;
|
|||
|
|
begin
|
|||
|
|
AsignarDataModule;
|
|||
|
|
end;
|
|||
|
|
|
|||
|
|
destructor TPagosClienteController.Destroy;
|
|||
|
|
begin
|
|||
|
|
FDataModule := NIL;
|
|||
|
|
inherited;
|
|||
|
|
end;
|
|||
|
|
|
|||
|
|
function TPagosClienteController.Eliminar(APagoCliente: IBizPagosCliente): Boolean;
|
|||
|
|
{ En el caso de eliminar un cobro del recibo devuelve true, mientras que si lo que
|
|||
|
|
se borra es una devoluci<EFBFBD>n devuelve false}
|
|||
|
|
begin
|
|||
|
|
Result := False;
|
|||
|
|
|
|||
|
|
if not Assigned(APagoCliente) then
|
|||
|
|
raise Exception.Create ('IBizPagosCliente no asignado');
|
|||
|
|
|
|||
|
|
ShowHourglassCursor;
|
|||
|
|
try
|
|||
|
|
if (APagoCliente.State in dsEditModes) then
|
|||
|
|
APagoCliente.Cancel;
|
|||
|
|
|
|||
|
|
APagoCliente.Last;
|
|||
|
|
Result := (APagoCliente.TIPO = CTE_PAGO);
|
|||
|
|
APagoCliente.Delete;
|
|||
|
|
//Todo lo haremos en memoria ya que los pagos no tienen entidad propia
|
|||
|
|
//APagosCliente.DataTable.ApplyUpdates;
|
|||
|
|
finally
|
|||
|
|
HideHourglassCursor;
|
|||
|
|
end;
|
|||
|
|
end;
|
|||
|
|
|
|||
|
|
function TPagosClienteController.EliminarTodo(APagosCliente: IBizPagosCliente): Boolean;
|
|||
|
|
begin
|
|||
|
|
if Assigned(APagosCliente) then
|
|||
|
|
begin
|
|||
|
|
if not APagosCliente.DataTable.Active then
|
|||
|
|
APagosCliente.DataTable.Active := True;
|
|||
|
|
APagosCliente.DataTable.ClearRows;
|
|||
|
|
//Todo lo haremos en memoria ya que los pagos no tienen entidad propia
|
|||
|
|
//APagosCliente.DataTable.ApplyUpdates;
|
|||
|
|
Result := True;
|
|||
|
|
end;
|
|||
|
|
end;
|
|||
|
|
|
|||
|
|
procedure TPagosClienteController.Modificar(APagosCliente: IBizPagosCliente; const Fecha: String);
|
|||
|
|
begin
|
|||
|
|
APagosCliente.DataTable.Edit;
|
|||
|
|
APagosCliente.FECHA_PAGO := StrToDate(Fecha);
|
|||
|
|
APagosCliente.DataTable.Post;
|
|||
|
|
end;
|
|||
|
|
|
|||
|
|
end.
|