2007-11-05 17:59:28 +00:00
{
= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
Copyright ( <EFBFBD> ) 2 0 0 7 . 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 uRecibosClienteController;
interface
uses
Classes, SysUtils, uDADataTable, uControllerBase,
uPagosClienteController, uClientesController,
uBizRecibosCliente, uIDataModuleRecibosCliente;
type
2008-08-22 14:52:35 +00:00
IRecibosClienteController = interface( IControllerBase)
2007-11-05 17:59:28 +00:00
[ '{CBC8BDB8-FBE0-4D54-B2F1-A9330E8339EB}' ]
function GetPagosController: IPagosClienteController;
procedure SetPagosController( const Value: IPagosClienteController) ;
property PagosController: IPagosClienteController read GetPagosController write SetPagosController;
procedure Anadir( ARecibosCliente : IBizRecibosCliente) ;
function Eliminar( ARecibosCliente : IBizRecibosCliente) : Boolean ;
function AnadirPago( ARecibosCliente : IBizRecibosCliente; FechaPago: String = '' ) : Boolean ;
procedure ModificarPago( ARecibosCliente : IBizRecibosCliente) ;
function EliminarPago( ARecibosCliente : IBizRecibosCliente) : Boolean ;
function EliminarTodo( ARecibosCliente : IBizRecibosCliente) : Boolean ;
function Guardar( ARecibosCliente : IBizRecibosCliente) : Boolean ;
procedure DescartarCambios( ARecibosCliente : IBizRecibosCliente) ;
function Duplicar( ARecibosCliente: IBizRecibosCliente) : IBizRecibosCliente;
function Nuevo : IBizRecibosCliente;
procedure RecuperarCliente( AReciboCliente : IBizRecibosCliente) ;
function Buscar( const ID: Integer ) : IBizRecibosCliente;
2008-11-10 11:29:57 +00:00
function BuscarTodos: IBizRecibosCliente; overload ;
function BuscarTodos( const ID_CLIENTE: integer ) : IBizRecibosCliente; overload ;
2007-11-05 17:59:28 +00:00
function BuscarRecibosRemesa( const ID_REMESA: Integer ) : IBizRecibosCliente;
function BuscarRecibosFactura( const ID_FACTURA: Integer ) : IBizRecibosCliente;
function BuscarRecibosACompensar( const Recibo: IBizRecibosCliente) : IBizRecibosCliente;
function BuscarRecibosARemesar: IBizRecibosCliente;
2008-11-10 11:29:57 +00:00
procedure VerTodos( ARecibosCliente: IBizRecibosCliente;
const AVerModal : Boolean = False ; const AWindowCaption: String = '' ;
const AHeaderText: String = '' ) ;
2007-11-05 17:59:28 +00:00
procedure Ver( ARecibosCliente: IBizRecibosCliente) ;
function ExtraerSeleccionados( ARecibosCliente: IBizRecibosCliente) : IBizRecibosCliente;
function ElegirRecibos( ARecibos : IBizRecibosCliente; AMensaje: String ; AMultiSelect: Boolean ) : IBizRecibosCliente;
procedure AsignarRemesa( ARecibos : IBizRecibosCliente; ID_REMESA: Integer ) ;
procedure QuitarRemesa( ARecibos : IBizRecibosCliente) ;
procedure SetSituacionCobrados( ARecibos : IBizRecibosCliente; WithDeltas: Boolean = False ) ;
function ElegirRecibosCompensados( ARecibo : IBizRecibosCliente) : Boolean ;
procedure QuitarReciboCompensado( ARecibo : IBizRecibosCliente) ;
procedure Preview( ARecibosCliente : IBizRecibosCliente; AllItems: Boolean = false ) ;
procedure Print( ARecibosCliente : IBizRecibosCliente; AllItems: Boolean = false ) ;
end ;
2008-08-22 14:52:35 +00:00
TRecibosClienteController = class( TControllerBase, IRecibosClienteController)
2007-11-05 17:59:28 +00:00
private
function ImporteTotalModificado( ARecibosCliente: IBizRecibosCliente;
var ImporteRestante: Currency ) : Boolean ;
2007-11-18 17:23:37 +00:00
procedure FiltrarEmpresa( ARecibo: IBizRecibosCliente) ;
2007-11-05 17:59:28 +00:00
protected
FDataModule : IDataModuleRecibosCliente;
FPagosController : IPagosClienteController;
FClienteController : IClientesController;
function GetPagosController: IPagosClienteController;
procedure SetPagosController( const Value: IPagosClienteController) ;
function _Vacio : IBizRecibosCliente;
function ValidarReciboCliente( ARecibosCliente: IBizRecibosCliente) : Boolean ;
procedure AsignarDataModule;
function DarNuevaReferencia( ID_FACTURA : Integer ; REFERENCIA: String ) : String ;
public
property PagosController: IPagosClienteController read GetPagosController write SetPagosController;
2007-11-22 19:09:07 +00:00
constructor Create; override ;
2007-11-05 17:59:28 +00:00
destructor Destroy; override ;
procedure RecuperarCliente( AReciboCliente : IBizRecibosCliente) ;
procedure Anadir( ARecibosCliente : IBizRecibosCliente) ;
function AnadirPago( ARecibosCliente : IBizRecibosCliente; FechaPago: String = '' ) : Boolean ;
procedure ModificarPago( ARecibosCliente : IBizRecibosCliente) ;
function Eliminar( ARecibosCliente : IBizRecibosCliente) : Boolean ;
function EliminarPago( ARecibosCliente : IBizRecibosCliente) : Boolean ;
function EliminarTodo( ARecibosCliente : IBizRecibosCliente) : Boolean ;
function Guardar( ARecibosCliente : IBizRecibosCliente) : Boolean ;
procedure DescartarCambios( ARecibosCliente : IBizRecibosCliente) ;
function Duplicar( ARecibosCliente: IBizRecibosCliente) : IBizRecibosCliente;
function Nuevo : IBizRecibosCliente;
function Buscar( const ID: Integer ) : IBizRecibosCliente;
2008-11-10 11:29:57 +00:00
function BuscarTodos: IBizRecibosCliente; overload ;
function BuscarTodos( const ID_CLIENTE: integer ) : IBizRecibosCliente; overload ;
2007-11-05 17:59:28 +00:00
function BuscarRecibosRemesa( const ID_REMESA: Integer ) : IBizRecibosCliente;
function BuscarRecibosFactura( const ID_FACTURA: Integer ) : IBizRecibosCliente;
function BuscarRecibosACompensar( const Recibo: IBizRecibosCliente) : IBizRecibosCliente;
function BuscarRecibosARemesar: IBizRecibosCliente;
2008-11-10 11:29:57 +00:00
procedure VerTodos( ARecibosCliente: IBizRecibosCliente;
const AVerModal : Boolean = False ; const AWindowCaption: String = '' ;
const AHeaderText: String = '' ) ;
2007-11-05 17:59:28 +00:00
procedure Ver( ARecibosCliente: IBizRecibosCliente) ;
function ExtraerSeleccionados( ARecibosCliente: IBizRecibosCliente) : IBizRecibosCliente;
function ElegirRecibos( ARecibos : IBizRecibosCliente; AMensaje: String ; AMultiSelect: Boolean ) : IBizRecibosCliente;
function ElegirRecibosCompensados( ARecibo : IBizRecibosCliente) : Boolean ;
procedure AsignarRemesa( ARecibos : IBizRecibosCliente; ID_REMESA: Integer ) ;
procedure QuitarRemesa( ARecibos : IBizRecibosCliente) ;
procedure QuitarReciboCompensado( ARecibo : IBizRecibosCliente) ;
procedure SetSituacionCobrados( ARecibos : IBizRecibosCliente; WithDeltas: Boolean = False ) ;
procedure Preview( ARecibosCliente : IBizRecibosCliente; AllItems: Boolean = false ) ;
procedure Print( ARecibosCliente : IBizRecibosCliente; AllItems: Boolean = false ) ;
end ;
implementation
uses
Forms, uNumUtils, cxControls, DB, uEditorRegistryUtils, Dialogs,
2007-11-18 15:07:51 +00:00
uDAInterfaces, uDataTableUtils, uDataModuleUsuarios, uFactuGES_App,
2007-11-05 17:59:28 +00:00
uDateUtils, uROTypes, DateUtils, Controls, Windows, Variants,
2008-08-22 14:52:35 +00:00
uRecibosClienteReportController, uBizContactos, uDADelta, uIntegerListUtils,
2007-11-05 17:59:28 +00:00
schRecibosClienteClient_Intf, uIEditorRecibosCliente, uIEditorReciboCliente,
2008-11-10 11:29:57 +00:00
uIEditorElegirRecibosCliente, uDataModuleRecibosCliente, uIEditorFechaPago,
uStringsUtils;
2007-11-05 17:59:28 +00:00
{ TRecibosClienteController }
procedure TRecibosClienteController. Anadir( ARecibosCliente: IBizRecibosCliente) ;
begin
ARecibosCliente. Insert;
end ;
function TRecibosClienteController. AnadirPago( ARecibosCliente: IBizRecibosCliente; FechaPago: String = '' ) : Boolean ;
var
AEditor : IEditorFechaPago;
begin
Result : = False ;
if ( Length( ARecibosCliente. REFERENCIA_REMESA) = 0 ) or
( Application. MessageBox( PChar( 'Este recibo est<73> remesado en la remesa de referencia ' + ARecibosCliente. REFERENCIA_REMESA + '.' + #10 #13 + 'Si a<> ade una devoluci<63> n, el recibo quedar<61> libre y podr<64> ser incluido en otra remesa diferente.' + #10 #13 + '<27> Desea continuar?' ) , 'Atenci<63> n' , MB_YESNO) = IDYES) then
begin
//Pedimos la fecha del pago
if ( Length( FechaPago) = 0 ) then
begin
CreateEditor( 'EditorFechaPago' , IEditorFechaPago, AEditor) ;
if Assigned( AEditor) then
try
if ( AEditor. ShowModal = mrOk) then
FechaPago : = DateToStr( AEditor. FechaPago) ;
AEditor. Release;
finally
AEditor : = NIL ;
end ;
end ;
// Se cancela la operaci<63> n
if Length( FechaPago) = 0 then
Exit;
//Liberamos el recibo aunque ya este libre
if not ARecibosCliente. DataTable. Editing then
ARecibosCliente. DataTable. Edit;
ARecibosCliente. ID_REMESA : = 0 ;
ARecibosCliente. REFERENCIA_REMESA : = '' ;
ARecibosCliente. DataTable. Post;
end
// Se cancela la operaci<63> n
else
Exit;
//Finalmente a<> adimos el pago (cobro o devolucion)
if PagosController. Anadir( ARecibosCliente. Pagos, FechaPago) then
begin
ARecibosCliente. Edit;
ARecibosCliente. SITUACION : = CTE_COBRADO;
Result : = True ;
end
//Podremos modificar si anulamos el cobro mediante una devoluci<63> n
else
begin
ARecibosCliente. Edit;
ARecibosCliente. SITUACION : = CTE_DEVUELTO;
Result : = False ;
end ;
end ;
procedure TRecibosClienteController. AsignarDataModule;
begin
FDataModule : = TDataModuleRecibosCliente. Create( Nil ) ;
end ;
procedure TRecibosClienteController. AsignarRemesa( ARecibos: IBizRecibosCliente; ID_REMESA: Integer ) ;
begin
if Assigned( ARecibos) then
begin
With ARecibos. DataTable do
begin
First;
While not EOF do
begin
if ( ARecibos. ID_REMESA < > ID_REMESA) then
begin
ARecibos. Edit;
//A<> adimos el cobro automatico por la remesa y volvemos a asignar ID
//para que asigne un ID nuevo para el pago, porque aqui si hay maestro-detalle
AnadirPago( ARecibos, DateToStr( Date) ) ; //->Ojo el orden es importante
ARecibos. ID_REMESA : = ID_REMESA;
end ;
Next;
end ;
end ;
end ;
end ;
function TRecibosClienteController. BuscarTodos: IBizRecibosCliente;
begin
Result : = FDataModule. GetItems;
2007-11-18 17:23:37 +00:00
FiltrarEmpresa( Result ) ;
2007-11-05 17:59:28 +00:00
end ;
function TRecibosClienteController. BuscarRecibosACompensar( const Recibo: IBizRecibosCliente) : IBizRecibosCliente;
2007-11-14 19:41:42 +00:00
var
Condicion: TDAWhereExpression;
2007-11-05 17:59:28 +00:00
begin
if not Assigned( Recibo) then
raise Exception. Create ( 'IBizReciboCliente no asignado (BuscarRecibosACompensar)' ) ;
ShowHourglassCursor;
try
Result : = BuscarTodos;
2007-11-14 19:41:42 +00:00
with Result . DataTable. DynamicWhere do
begin
2007-11-05 17:59:28 +00:00
//No podr<64> compensarse un recibo a si mismo
2007-11-14 19:41:42 +00:00
Condicion : = NewBinaryExpression( NewField( '' , fld_RecibosClienteID) , NewConstant( Recibo. ID, datInteger) , dboNotEqual) ;
2007-11-05 17:59:28 +00:00
2007-11-14 19:41:42 +00:00
if IsEmpty then
Expression : = Condicion
else
Expression : = NewBinaryExpression( Expression, Condicion, dboAnd) ;
end ;
2007-11-05 17:59:28 +00:00
2007-11-14 19:41:42 +00:00
with Result . DataTable. DynamicWhere do
begin
2007-11-05 17:59:28 +00:00
//Solo podr<64> compensar recibos del mismo cliente
2007-11-14 19:41:42 +00:00
Condicion : = NewBinaryExpression( NewField( '' , fld_RecibosClienteID_CLIENTE) , NewConstant( Recibo. ID_CLIENTE, datInteger) , dboEqual) ;
2007-11-05 17:59:28 +00:00
2007-11-14 19:41:42 +00:00
if IsEmpty then
Expression : = Condicion
else
Expression : = NewBinaryExpression( Expression, Condicion, dboAnd) ;
end ;
2007-11-05 17:59:28 +00:00
2007-11-14 19:41:42 +00:00
with Result . DataTable. DynamicWhere do
begin
2007-11-05 17:59:28 +00:00
//Omitimos los recibos compensados
2007-11-14 19:41:42 +00:00
Condicion : = NewBinaryExpression( NewField( '' , fld_RecibosClienteID_RECIBO_COMPENSADO) , NewNull, dboEqual) ;
2007-11-05 17:59:28 +00:00
2007-11-14 19:41:42 +00:00
if IsEmpty then
Expression : = Condicion
else
Expression : = NewBinaryExpression( Expression, Condicion, dboAnd) ;
end ;
2007-11-05 17:59:28 +00:00
2007-11-14 19:41:42 +00:00
with Result . DataTable. DynamicWhere do
begin
2007-11-05 17:59:28 +00:00
//No podr<64> compensarse recibos que estan cobrados
2007-11-14 19:41:42 +00:00
Condicion : = NewBinaryExpression( NewField( '' , fld_RecibosClienteSITUACION) , NewConstant( CTE_COBRADO, datString) , dboNotEqual) ;
if IsEmpty then
Expression : = Condicion
else
Expression : = NewBinaryExpression( Expression, Condicion, dboAnd) ;
2007-11-05 17:59:28 +00:00
end ;
2007-11-14 19:41:42 +00:00
2007-11-05 17:59:28 +00:00
finally
HideHourglassCursor;
end ;
end ;
constructor TRecibosClienteController. Create;
begin
inherited ;
AsignarDataModule;
FPagosController : = TPagosClienteController. Create;
FClienteController : = TClientesController. Create;
// FPagosController.addObservador(Self); //PETA NO SE PORQUE
end ;
function TRecibosClienteController. Buscar( const ID: Integer ) : IBizRecibosCliente;
begin
Result : = ( FDataModule as IDataModuleRecibosCliente) . GetItem( ID) ;
2007-11-18 17:23:37 +00:00
FiltrarEmpresa( Result ) ;
2007-11-05 17:59:28 +00:00
end ;
function TRecibosClienteController. BuscarRecibosFactura( const ID_FACTURA: Integer ) : IBizRecibosCliente;
2007-11-14 19:41:42 +00:00
var
Condicion: TDAWhereExpression;
2007-11-05 17:59:28 +00:00
begin
ShowHourglassCursor;
try
Result : = BuscarTodos;
2007-11-14 19:41:42 +00:00
with Result . DataTable. DynamicWhere do
2007-11-05 17:59:28 +00:00
begin
2007-11-14 19:41:42 +00:00
// (ID = :ID)
Condicion : = NewBinaryExpression( NewField( '' , fld_RecibosClienteID_FACTURA) , NewConstant( ID_FACTURA, datInteger) , dboEqual) ;
if IsEmpty then
Expression : = Condicion
else
Expression : = NewBinaryExpression( Expression, Condicion, dboAnd) ;
2007-11-05 17:59:28 +00:00
end ;
2007-11-14 19:41:42 +00:00
2007-11-05 17:59:28 +00:00
finally
HideHourglassCursor;
end ;
end ;
function TRecibosClienteController. BuscarRecibosARemesar: IBizRecibosCliente;
2007-11-18 17:23:37 +00:00
var
Condicion: TDAWhereExpression;
2007-11-05 17:59:28 +00:00
begin
ShowHourglassCursor;
try
Result : = BuscarTodos;
2007-11-18 17:23:37 +00:00
with Result . DataTable. DynamicWhere do
2007-11-05 17:59:28 +00:00
begin
2007-11-18 17:23:37 +00:00
//No podr<64> compensarse un recibo ya compensado
Condicion : = NewBinaryExpression( NewField( '' , fld_RecibosClienteID_RECIBO_COMPENSADO) , NewNull( ) , dboEqual) ;
2007-11-05 17:59:28 +00:00
2007-11-18 17:23:37 +00:00
if IsEmpty then
Expression : = Condicion
else
Expression : = NewBinaryExpression( Expression, Condicion, dboAnd) ;
end ;
with Result . DataTable. DynamicWhere do
begin
2007-11-05 17:59:28 +00:00
//Solo dejaremos remesar aquellos recibos que no esten cobrados (Pendientes/Devueltos)
2007-11-18 17:23:37 +00:00
Condicion : = NewBinaryExpression( NewField( '' , fld_RecibosClienteSITUACION) , NewConstant( CTE_COBRADO, datString) , dboNotEqual) ;
if IsEmpty then
Expression : = Condicion
else
Expression : = NewBinaryExpression( Expression, Condicion, dboAnd) ;
2007-11-05 17:59:28 +00:00
end ;
finally
HideHourglassCursor;
end ;
end ;
function TRecibosClienteController. BuscarRecibosRemesa( const ID_REMESA: Integer ) : IBizRecibosCliente;
2007-11-18 17:23:37 +00:00
var
Condicion: TDAWhereExpression;
2007-11-05 17:59:28 +00:00
begin
ShowHourglassCursor;
try
Result : = BuscarTodos;
2007-11-18 17:23:37 +00:00
// Filtrar los recibos de una remesa determinada
with Result . DataTable. DynamicWhere do
2007-11-05 17:59:28 +00:00
begin
2007-11-18 17:23:37 +00:00
// (ID_REMESA >= ID)
Condicion : = NewBinaryExpression( NewField( '' , fld_RecibosClienteID_REMESA) , NewConstant( ID_REMESA, datInteger) , dboEqual) ;
if IsEmpty then
Expression : = Condicion
else
Expression : = NewBinaryExpression( Expression, Condicion, dboAnd) ;
2007-11-05 17:59:28 +00:00
end ;
2007-11-18 17:23:37 +00:00
2007-11-05 17:59:28 +00:00
finally
HideHourglassCursor;
end ;
end ;
2008-11-10 11:29:57 +00:00
function TRecibosClienteController. BuscarTodos(
const ID_CLIENTE: integer ) : IBizRecibosCliente;
var
Condicion: TDAWhereExpression;
begin
ShowHourglassCursor;
try
Result : = BuscarTodos;
with Result . DataTable. DynamicWhere do
begin
// ID_CLIENTE
Condicion : = NewBinaryExpression( NewField( '' , fld_RecibosClienteID_CLIENTE) ,
NewConstant( ID_Cliente, datInteger) , dboEqual) ;
if IsEmpty then
Expression : = Condicion
else
Expression : = NewBinaryExpression( Expression, Condicion, dboAnd) ;
end ;
finally
HideHourglassCursor;
end ;
end ;
2007-11-05 17:59:28 +00:00
function TRecibosClienteController. _Vacio: IBizRecibosCliente;
begin
Result : = Buscar( ID_NULO) ;
end ;
function TRecibosClienteController. DarNuevaReferencia( ID_FACTURA: Integer ; REFERENCIA: String ) : String ;
var
ARecibosCliente: IBizRecibosCliente;
NumReferencia : Integer ;
Cadena : String ;
begin
try
ARecibosCliente : = BuscarRecibosFactura( ID_FACTURA) ;
ARecibosCliente. DataTable. Active : = True ;
NumReferencia : = ARecibosCliente. DataTable. RecordCount;
Cadena : = Copy( REFERENCIA, 0 , Pos( '-' , REFERENCIA) ) ;
Result : = Cadena + ' ' + IntToStr( ( NumReferencia + 1 ) ) ;
finally
ARecibosCliente : = Nil ;
end ;
end ;
procedure TRecibosClienteController. DescartarCambios( ARecibosCliente: IBizRecibosCliente) ;
begin
if not Assigned( ARecibosCliente) then
raise Exception. Create ( 'IBizRecibosCliente no asignado' ) ;
ShowHourglassCursor;
try
if ( ARecibosCliente. State in dsEditModes) then
ARecibosCliente. Cancel;
ARecibosCliente. DataTable. CancelUpdates;
finally
HideHourglassCursor;
end ;
end ;
destructor TRecibosClienteController. Destroy;
begin
FDataModule : = NIL ;
FPagosController : = NIL ;
FClienteController : = NIL ;
inherited ;
end ;
function TRecibosClienteController. Duplicar( ARecibosCliente: IBizRecibosCliente) : IBizRecibosCliente;
begin
Result : = Self. _Vacio;
ShowHourglassCursor;
try
DuplicarRegistros( ARecibosCliente. DataTable, Result . DataTable, mdrActual) ;
// Descomentar esto si hay detalles
2007-11-18 15:07:51 +00:00
// (EN ESTE CASO NO NOS INTERESA COPIAR LOS PAGOS DEL RECIBO DUPLICADO)
2007-11-05 17:59:28 +00:00
// DuplicarRegistros(ARecibosCliente.Detalles.DataTable, Result.Detalles.DataTable, mdrTodos);
// <20> CUIDADO! Hay que dejar algunos campos como si fuera todo nuevo
Result . Edit;
with Result do
begin
// Ejemplos
// ID_EMPRESA := dmUsuarios.IDEmpresaActual;
// USUARIO := dmUsuarios.LoginInfo.Usuario;
// REFERENCIA := ''; //Para que se asigne una nueva
// FECHA_FACTURA := DateOf(Now);
// SITUACION := SITUACION_PENDIENTE;
end ;
Result . Post;
finally
HideHourglassCursor;
end ;
end ;
function TRecibosClienteController. ValidarReciboCliente( ARecibosCliente: IBizRecibosCliente) : Boolean ;
begin
if not Assigned( ARecibosCliente) then
raise Exception. Create ( 'IBizRecibosCliente no asignado' ) ;
if ( ARecibosCliente. DataTable. State in dsEditModes) then
ARecibosCliente. DataTable. Post;
// Tambien hacemos post de sus tablas hija
if ( ARecibosCliente. Pagos. DataTable. State in dsEditModes) then
ARecibosCliente. Pagos. DataTable. Post;
if ARecibosCliente. DataTable. FieldByName( fld_RecibosClienteFECHA_EMISION) . IsNull then
raise Exception. Create( 'Debe indicar la fecha de emisi<73> n del recibo.' ) ;
if ARecibosCliente. DataTable. FieldByName( fld_RecibosClienteFECHA_VENCIMIENTO) . IsNull then
raise Exception. Create( 'Debe indicar la fecha de vencimiento del recibo.' ) ;
{ Asegurarse de valores en campos "autom<6F> ticos" tanto
en MODIFICACI<EFBFBD> N como en INSERCI<EFBFBD> N. }
ARecibosCliente. Edit;
try
2007-11-18 15:07:51 +00:00
ARecibosCliente. USUARIO : = AppFactuGES. UsuarioActivo. UserName;
2007-11-05 17:59:28 +00:00
finally
ARecibosCliente. Post;
end ;
Result : = True ;
end ;
procedure TRecibosClienteController. Ver( ARecibosCliente: IBizRecibosCliente) ;
var
AEditor : IEditorReciboCliente;
begin
AEditor : = NIL ;
ShowHourglassCursor;
try
RecuperarCliente( ARecibosCliente) ;
CreateEditor( 'EditorReciboCliente' , IEditorReciboCliente, AEditor) ;
2007-11-18 18:42:04 +00:00
if Assigned( AEditor) then
with AEditor do
begin
Controller : = Self; //OJO ORDEN MUY IMPORTANTE
Recibo : = ARecibosCliente;
ShowModal;
Release;
end ;
2007-11-05 17:59:28 +00:00
finally
2007-11-18 18:42:04 +00:00
AEditor : = NIL ;
2007-11-05 17:59:28 +00:00
HideHourglassCursor;
end ;
end ;
2008-11-10 11:29:57 +00:00
procedure TRecibosClienteController. VerTodos( ARecibosCliente: IBizRecibosCliente;
const AVerModal : Boolean = False ; const AWindowCaption: String = '' ;
const AHeaderText: String = '' ) ;
2007-11-05 17:59:28 +00:00
var
AEditor : IEditorRecibosCliente;
begin
AEditor : = NIL ;
ShowHourglassCursor;
try
CreateEditor( 'EditorRecibosCliente' , IEditorRecibosCliente, AEditor) ;
if Assigned( AEditor) then
with AEditor do
begin
2008-11-10 11:29:57 +00:00
if not EsCadenaVacia( AWindowCaption) then
AEditor. WindowCaption : = AWindowCaption;
if not EsCadenaVacia( AHeaderText) then
AEditor. HeaderText : = AHeaderText;
2007-11-14 19:41:42 +00:00
Controller : = Self; //OJO ORDEN MUY IMPORTANTE
2007-11-05 17:59:28 +00:00
RecibosCliente : = ARecibosCliente;
MultiSelect : = True ;
2008-11-10 11:29:57 +00:00
if AVerModal then
ShowModal
else
ShowEmbedded;
2007-11-05 17:59:28 +00:00
end ;
finally
AEditor : = NIL ;
HideHourglassCursor;
end ;
end ;
function TRecibosClienteController. ElegirRecibos( ARecibos: IBizRecibosCliente; AMensaje: String ; AMultiSelect: Boolean ) : IBizRecibosCliente;
var
AEditor : IEditorElegirRecibosCliente;
begin
Result : = NIL ;
CreateEditor( 'EditorElegirRecibosCliente' , IEditorElegirRecibosCliente, AEditor) ;
try
with AEditor do
begin
Controller : = Self;
RecibosCliente : = ARecibos;
MultiSelect : = AMultiSelect;
Mensaje : = AMensaje;
if IsPositiveResult( ShowModal) then
Result : = RecibosClienteSeleccionados;
Release;
end ;
finally
AEditor : = NIL ;
end ;
end ;
function TRecibosClienteController. ElegirRecibosCompensados( ARecibo: IBizRecibosCliente) : Boolean ;
var
ARecibosACompensar: IBizRecibosCliente;
begin
2008-05-20 18:50:02 +00:00
Result : = False ;
2007-11-05 17:59:28 +00:00
ARecibosACompensar : = Self. ElegirRecibos( BuscarRecibosACompensar( ARecibo) , 'Elija los recibos que desea compensar' , True ) ;
if Assigned( ARecibosACompensar) then
begin
ShowHourglassCursor;
try
DuplicarRegistros( ARecibosACompensar. DataTable, ARecibo. RecibosCompensados. DataTable, mdrTodos, True , True , False ) ;
Result : = True ;
finally
HideHourglassCursor;
ARecibosACompensar : = Nil ;
end ;
end ;
end ;
function TRecibosClienteController. Eliminar( ARecibosCliente: IBizRecibosCliente) : Boolean ;
begin
if not Assigned( ARecibosCliente) then
raise Exception. Create ( 'IBizRecibosCliente no asignado' ) ;
ShowHourglassCursor;
try
if ( ARecibosCliente. State in dsEditModes) then
ARecibosCliente. Cancel;
ARecibosCliente. Delete;
ARecibosCliente. DataTable. ApplyUpdates;
HideHourglassCursor;
Result : = True ;
finally
HideHourglassCursor;
end ;
end ;
function TRecibosClienteController. EliminarPago( ARecibosCliente: IBizRecibosCliente) : Boolean ;
begin
Result : = PagosController. Eliminar( ARecibosCliente. Pagos) ;
end ;
function TRecibosClienteController. EliminarTodo( ARecibosCliente: IBizRecibosCliente) : Boolean ;
begin
2008-05-20 18:50:02 +00:00
Result : = False ;
2007-11-05 17:59:28 +00:00
if Assigned( ARecibosCliente) then
begin
if not ARecibosCliente. DataTable. Active then
ARecibosCliente. DataTable. Active : = True ;
ARecibosCliente. DataTable. ClearRows;
ARecibosCliente. DataTable. ApplyUpdates;
Result : = True ;
end ;
end ;
procedure TRecibosClienteController. RecuperarCliente( AReciboCliente: IBizRecibosCliente) ;
begin
AReciboCliente. _Cliente : = ( FClienteController. Buscar( AReciboCliente. ID_Cliente) as IBizCliente) ;
end ;
function TRecibosClienteController. GetPagosController: IPagosClienteController;
begin
Result : = FPagosController;
end ;
procedure TRecibosClienteController. SetPagosController( const Value: IPagosClienteController) ;
begin
FPagosController : = Value;
end ;
procedure TRecibosClienteController. SetSituacionCobrados( ARecibos: IBizRecibosCliente; WithDeltas: Boolean ) ;
begin
if Assigned( ARecibos) then
begin
ARecibos. DataTable. DisableControls;
try
DesconectarTabla( ARecibos. DataTable) ;
with ARecibos. DataTable do
begin
First;
while not Eof do
begin
if not Editing then Edit;
ARecibos. SITUACION : = CTE_COBRADO;
Post;
Next;
end ;
First;
end ;
finally
ConectarTabla( ARecibos. DataTable) ;
ARecibos. DataTable. EnableControls;
end ;
end ;
end ;
function TRecibosClienteController. ImporteTotalModificado( ARecibosCliente : IBizRecibosCliente; var ImporteRestante: Currency ) : Boolean ;
2008-01-15 10:43:13 +00:00
var
HayCambio: TDADeltaChange;
2007-11-05 17:59:28 +00:00
begin
Result : = False ;
ImporteRestante : = 0 ;
HayCambio : = ARecibosCliente. DataTable. Delta. FindChange( ARecibosCliente. RecNo) ;
if ( Assigned( HayCambio) ) and
( HayCambio. OldValueByName[ fld_RecibosClienteIMPORTE] < > 0 ) then
begin
ImporteRestante : = HayCambio. OldValueByName[ fld_RecibosClienteIMPORTE] - ARecibosCliente. IMPORTE;
if ImporteRestante < > 0 then
Result : = True ;
end ;
end ;
function TRecibosClienteController. Guardar( ARecibosCliente: IBizRecibosCliente) : Boolean ;
var
ANuevoReciboCliente : IBizRecibosCliente;
ImporteRestante : Currency ;
begin
Result : = False ;
ANuevoReciboCliente : = NIL ;
ImporteRestante : = 0 ;
if ValidarReciboCliente( ARecibosCliente) then
begin
ShowHourglassCursor;
try
//Si el importe ha cambiado se debe hacer un recibo nuevo con el importe restante
if ImporteTotalModificado( ARecibosCliente, ImporteRestante) then
begin
ANuevoReciboCliente : = Duplicar( ARecibosCliente) ;
ANuevoReciboCliente. Edit;
ANuevoReciboCliente. REFERENCIA : = DarNuevaReferencia( ARecibosCliente. ID_FACTURA, ARecibosCliente. REFERENCIA) ;
// ANuevoReciboCliente.ID := FDataModule.GetNextID(ARecibosCliente.DataTable.LogicalName);
ANuevoReciboCliente. IMPORTE : = ImporteRestante;
ANuevoReciboCliente. DESCRIPCION : = 'RECIBO ' + ANuevoReciboCliente. REFERENCIA + ' - ' + CifraToLetras( ImporteRestante) ;
ANuevoReciboCliente. Post;
end ;
//Primero debemos hacer el ApplyUpdates del recibo inicial por si fallase
//As<41> no se har<61> a el nuevo
ARecibosCliente. DataTable. ApplyUpdates;
if Assigned( ANuevoReciboCliente) then
ANuevoReciboCliente. DataTable. ApplyUpdates;
Result : = True ;
finally
ANuevoReciboCliente : = NIL ;
HideHourglassCursor;
end ;
end ;
end ;
procedure TRecibosClienteController. ModificarPago( ARecibosCliente: IBizRecibosCliente) ;
var
AEditor : IEditorFechaPago;
FechaPago: String ;
begin
2007-11-18 20:08:55 +00:00
try
//Pedimos la fecha del pago
CreateEditor( 'EditorFechaPago' , IEditorFechaPago, AEditor) ;
if Assigned( AEditor) then
FechaPago: = '' ;
if ( AEditor. ShowModal = mrOk) then
FechaPago : = DateToStr( AEditor. FechaPago) ;
AEditor. Release;
finally
AEditor : = NIL ;
end ;
2007-11-05 17:59:28 +00:00
if Length( FechaPago) > 0 then
PagosController. Modificar( ARecibosCliente. Pagos, FechaPago) ;
end ;
function TRecibosClienteController. Nuevo: IBizRecibosCliente;
var
ARecibo : IBizRecibosCliente;
begin
ARecibo : = Buscar( ID_NULO) ;
ARecibo. DataTable. Active : = True ;
Anadir( ARecibo) ;
Result : = ARecibo;
end ;
procedure TRecibosClienteController. QuitarReciboCompensado( ARecibo: IBizRecibosCliente) ;
var
IdRecibo: Variant ;
begin
IdRecibo : = ARecibo. RecibosCompensados. ID;
ARecibo. RecibosCompensados. DataTable. First;
while ARecibo. RecibosCompensados. DataTable. Locate( 'ID' , IdRecibo, [ ] ) do
begin
ARecibo. RecibosCompensados. DataTable. Delete;
ARecibo. RecibosCompensados. DataTable. First;
end ;
end ;
procedure TRecibosClienteController. QuitarRemesa( ARecibos: IBizRecibosCliente) ;
begin
if Assigned( ARecibos) then
begin
if ARecibos. Pagos. DataTable. RecordCount = 0 then
Exit;
//Eliminamos el cobro generado por la remesa y quitamos el ID_REMESA del recibo
ARecibos. Pagos. DataTable. Last;
ARecibos. Pagos. Delete;
ARecibos. DataTable. Edit;
ARecibos. ID_REMESA : = 0 ;
ARecibos. DataTable. Post;
end ;
end ;
function TRecibosClienteController. ExtraerSeleccionados( ARecibosCliente: IBizRecibosCliente) : IBizRecibosCliente;
var
ASeleccionados : IBizRecibosCliente;
begin
ASeleccionados : = ( Self. Buscar( ID_NULO) as IBizRecibosCliente) ;
2008-05-21 15:15:41 +00:00
CopyDataTableDA5( ARecibosCliente. DataTable, ASeleccionados. DataTable, True ) ;
2007-11-05 17:59:28 +00:00
Result : = ASeleccionados;
end ;
2007-11-18 17:23:37 +00:00
procedure TRecibosClienteController. FiltrarEmpresa( ARecibo: IBizRecibosCliente) ;
var
Condicion: TDAWhereExpression;
begin
if ARecibo. DataTable. Active then
ARecibo. DataTable. Active : = False ;
// Filtrar los recibos actuales por empresa
with ARecibo. DataTable. DynamicWhere do
begin
// (ID_EMPRESA >= ID)
Condicion : = NewBinaryExpression( NewField( '' , fld_RecibosClienteID_EMPRESA) , NewConstant( AppFactuGES. EmpresaActiva. ID, datInteger) , dboEqual) ;
if IsEmpty then
Expression : = Condicion
else
Expression : = NewBinaryExpression( Expression, Condicion, dboAnd) ;
end ;
end ;
2007-11-05 17:59:28 +00:00
procedure TRecibosClienteController. Preview( ARecibosCliente: IBizRecibosCliente; AllItems: Boolean = false ) ;
var
AReportController : IRecibosClienteReportController;
2008-08-22 14:52:35 +00:00
ID_Recibos: TIntegerList;
2007-11-05 17:59:28 +00:00
begin
AReportController : = TRecibosClienteReportController. Create;
2008-08-22 14:52:35 +00:00
ID_Recibos : = TIntegerList. Create;
2008-05-20 18:50:02 +00:00
2007-11-05 17:59:28 +00:00
try
//Si deseamos previsualizar todos los items del objeto albaran
if AllItems then
begin
with ARecibosCliente. DataTable do
begin
First;
while not EOF do
begin
2008-08-22 14:52:35 +00:00
ID_Recibos. Add( ARecibosCliente. ID) ;
2007-11-05 17:59:28 +00:00
Next;
end ;
end ;
end
//Solo previsualizamos el item seleccionado
else
2008-08-22 14:52:35 +00:00
ID_Recibos. Add( ARecibosCliente. ID) ;
2007-11-05 17:59:28 +00:00
2008-08-22 14:52:35 +00:00
AReportController. Preview( ID_Recibos) ;
2007-11-05 17:59:28 +00:00
finally
AReportController : = NIL ;
2008-08-22 14:52:35 +00:00
FreeANDNil( ID_Recibos) ;
2007-11-05 17:59:28 +00:00
end ;
end ;
procedure TRecibosClienteController. Print( ARecibosCliente: IBizRecibosCliente; AllItems: Boolean = false ) ;
var
AReportController : IRecibosClienteReportController;
2008-08-22 14:52:35 +00:00
ID_Recibos: TIntegerList;
2007-11-05 17:59:28 +00:00
begin
AReportController : = TRecibosClienteReportController. Create;
2008-08-22 14:52:35 +00:00
ID_Recibos : = TIntegerList. Create;
2008-05-20 18:50:02 +00:00
2007-11-05 17:59:28 +00:00
try
//Si deseamos previsualizar todos los items del objeto albaran
if AllItems then
begin
with ARecibosCliente. DataTable do
begin
First;
while not EOF do
begin
2008-08-22 14:52:35 +00:00
ID_Recibos. Add( ARecibosCliente. ID) ;
2007-11-05 17:59:28 +00:00
Next;
end ;
end ;
end
//Solo previsualizamos el item seleccionado
else
2008-08-22 14:52:35 +00:00
ID_Recibos. Add( ARecibosCliente. ID) ;
2007-11-05 17:59:28 +00:00
2008-08-22 14:52:35 +00:00
AReportController. Print( ID_Recibos) ;
2007-11-05 17:59:28 +00:00
finally
AReportController : = NIL ;
2008-08-22 14:52:35 +00:00
FreeANDNil( ID_Recibos) ;
2007-11-05 17:59:28 +00:00
end ;
end ;
end .