{ =============================================================================== Copyright (©) 2007. Rodax Software. =============================================================================== Los contenidos de este fichero son propiedad de Rodax Software titular del copyright. Este fichero sólo podrá ser copiado, distribuido y utilizado, en su totalidad o en parte, con el permiso escrito de Rodax Software, o de acuerdo con los términos y condiciones establecidas en el acuerdo/contrato bajo el que se suministra. ----------------------------------------------------------------------------- Web: www.rodax-software.com =============================================================================== Fecha primera versión: Versión actual: 1.0.0 Fecha versió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; Const IgnorarContabilidad: Integer; Const IdSubCuenta: Integer; Const SubCuenta: String; Const AReferenciaRemesa: String = ''): Boolean; procedure Modificar(APagosCliente: IBizPagosCliente; Const Fecha: String; Const IgnorarContabilidad: Integer; Const IdSubCuenta: Integer; Const SubCuenta: String; Const AReferenciaRemesa: String = ''); function Eliminar(APagoCliente : IBizPagosCliente): Boolean; function EliminarTodo(APagossCliente : IBizPagosCliente): Boolean; end; TPagosClienteController = class(TSujeto, IPagosClienteController) protected FDataModule : IDataModuleRecibosCliente; procedure AsignarDataModule; public constructor Create; virtual; destructor Destroy; override; function Anadir(APagosCliente: IBizPagosCliente; Const Fecha: String; Const IgnorarContabilidad: Integer; Const IdSubCuenta: Integer; Const SubCuenta: String; Const AReferenciaRemesa: String = ''): Boolean; procedure Modificar(APagosCliente: IBizPagosCliente; Const Fecha: String; Const IgnorarContabilidad: Integer; Const IdSubCuenta: Integer; Const SubCuenta: String; Const AReferenciaRemesa: String = ''); function Eliminar(APagoCliente : IBizPagosCliente): Boolean; function EliminarTodo(APagosCliente : IBizPagosCliente): Boolean; end; implementation uses cxControls, DB, uEditorRegistryUtils,Dialogs, uFactuGES_App, uBizEjercicios, uDAInterfaces, uDataTableUtils, uDataModuleUsuarios, uDateUtils, uROTypes, DateUtils, Controls, Windows, Variants, schRecibosClienteClient_Intf, uDataModuleRecibosCliente; { TPagosClienteController } function TPagosClienteController.Anadir(APagosCliente: IBizPagosCliente; Const Fecha: String; Const IgnorarContabilidad: Integer; Const IdSubCuenta: Integer; Const SubCuenta: String; Const AReferenciaRemesa: String = ''): Boolean; { Si el pago introducido es un pago y no una devolución devolvemos true en caso de ser una devolución devolvemos false} begin APagosCliente.Append; try if Length(Fecha) = 0 then APagosCliente.FECHA_PAGO := Date else APagosCliente.FECHA_PAGO := StrToDate(Fecha); if Length(AReferenciaRemesa) <> 0 then APagosCliente.TITULAR := AReferenciaRemesa; if (APagosCliente.DataTable.RecordCount = 0) or ((APagosCliente.DataTable.RecordCount mod 2) = 0) then APagosCliente.TIPO := CTE_PAGO else APagosCliente.TIPO := CTE_DEVOLUCION; APagosCliente.IGNORAR_CONTABILIDAD := IgnorarContabilidad; APagosCliente.CUENTA := IntToStr(IdSubCuenta); APagosCliente.SUBCUENTA := SubCuenta; APagosCliente.ESTADO_EJERCICIO := AppFactuGES.EjercicioActivo.ESTADO; APagosCliente.ASIENTO_PUNTEADO := -1; Result := (APagosCliente.TIPO = CTE_PAGO); finally APagosCliente.Post; end; end; procedure TPagosClienteController.AsignarDataModule; begin FDataModule := TDataModuleRecibosCliente.Create(Nil); 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ó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); if APagoCliente.ASIENTO_PUNTEADO > 0 then raise Exception.Create('El asiento asociado al cobro esta punteado por lo que no puede ser borrado.'); if APagoCliente.ESTADO_EJERCICIO = CTE_CERRADO then raise Exception.Create('El asiento asociado al cobro tiene el ejercicio cerrado por lo que no puede ser borrado.'); APagoCliente.Delete; //Todo lo haremos en memoria ya que los pagos no tienen entidad propia //APagoCliente.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; Const IgnorarContabilidad: Integer; Const IdSubCuenta: Integer; Const SubCuenta: String; Const AReferenciaRemesa: String = ''); begin APagosCliente.DataTable.Edit; APagosCliente.FECHA_PAGO := StrToDate(Fecha); if Length(AReferenciaRemesa) <> 0 then APagosCliente.TITULAR := AReferenciaRemesa; APagosCliente.IGNORAR_CONTABILIDAD := IgnorarContabilidad; APagosCliente.CUENTA := IntToStr(IdSubCuenta); APagosCliente.SUBCUENTA := SubCuenta; APagosCliente.DataTable.Post; end; end.