git-svn-id: https://192.168.0.254/svn/Proyectos.LuisLeon_FactuGES/trunk@2 c93665c3-c93d-084d-9b98-7d5f4a9c3376
480 lines
14 KiB
ObjectPascal
480 lines
14 KiB
ObjectPascal
{
|
|
===============================================================================
|
|
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 uOscCustomersController;
|
|
|
|
interface
|
|
|
|
uses
|
|
Classes, SysUtils, uDADataTable, uControllerBase,
|
|
|
|
uOscAddressBookController,
|
|
uBizOscCustomers, uIDataModuleTiendaWeb;
|
|
|
|
type
|
|
IOscCustomersController = interface(IObservador)
|
|
['{17765BA6-400E-4809-8548-F8EFCB94E40E}']
|
|
function Nuevo : IBizOscCustomer;
|
|
procedure Anadir(AOscCustomers : IBizOscCustomer);
|
|
function Eliminar(AOscCustomers : IBizOscCustomer): Boolean; overload;
|
|
function Guardar(AOscCustomers : IBizOscCustomer): Boolean;
|
|
procedure DescartarCambios(AOscCustomers : IBizOscCustomer);
|
|
function Duplicar(AOscCustomers: IBizOscCustomer): IBizOscCustomer;
|
|
|
|
function Buscar(const IDLocal: Integer): IBizOscCustomer;
|
|
function BuscarTodos: IBizOscCustomer;
|
|
procedure VerTodos(AOscCustomers: IBizOscCustomer);
|
|
procedure Ver(AOscCustomers: IBizOscCustomer);
|
|
function Localizar(AOscCustomers: IBizOscCustomer; AIDLocal: Integer): Boolean;
|
|
function DarListaOscCustomers: TStringList;
|
|
function ExtraerSeleccionados(AOscCustomers: IBizOscCustomer) : IBizOscCustomer;
|
|
function ElegirOscCustomers(AOscCustomers: IBizOscCustomer; AMensaje: String; AMultiSelect: Boolean): IBizOscCustomer;
|
|
|
|
// Descomentar esto si hay informe
|
|
// procedure Preview(AOscCustomers : IBizOscCustomer);
|
|
// procedure Print(AOscCustomers : IBizOscCustomer);
|
|
end;
|
|
|
|
TOscCustomersController = class(TObservador, IOscCustomersController)
|
|
protected
|
|
FDataModule : IDataModuleTiendaWeb;
|
|
FAddressBookController : IOscAddressBookController;
|
|
|
|
procedure RecibirAviso(ASujeto: ISujeto; ADataTable: IDAStronglyTypedDataTable); override;
|
|
function _Vacio : IBizOscCustomer;
|
|
|
|
function ValidarOscCustomers(AOscCustomers: IBizOscCustomer): Boolean;
|
|
procedure AsignarDataModule;
|
|
procedure AsignarID(AOscCustomers: IBizOscCustomer; const IDNuevo: Integer);
|
|
public
|
|
constructor Create; virtual;
|
|
destructor Destroy; override;
|
|
|
|
function Nuevo : IBizOscCustomer;
|
|
procedure Anadir(AOscCustomers : IBizOscCustomer);
|
|
function Eliminar(AOscCustomers : IBizOscCustomer): Boolean; overload;
|
|
function Guardar(AOscCustomers : IBizOscCustomer): Boolean;
|
|
procedure DescartarCambios(AOscCustomers : IBizOscCustomer);
|
|
function Duplicar(AOscCustomers: IBizOscCustomer): IBizOscCustomer;
|
|
|
|
function Buscar(const IDLocal: Integer): IBizOscCustomer;
|
|
function BuscarTodos: IBizOscCustomer;
|
|
procedure VerTodos(AOscCustomers: IBizOscCustomer);
|
|
procedure Ver(AOscCustomers: IBizOscCustomer);
|
|
function Localizar(AOscCustomers: IBizOscCustomer; AIDLocal: Integer): Boolean;
|
|
function DarListaOscCustomers: TStringList;
|
|
function ExtraerSeleccionados(AOscCustomers: IBizOscCustomer) : IBizOscCustomer;
|
|
function ElegirOscCustomers(AOscCustomers: IBizOscCustomer; AMensaje: String; AMultiSelect: Boolean): IBizOscCustomer;
|
|
|
|
// Descomentar esto si hay informe
|
|
// procedure Preview(AOscCustomers : IBizOscCustomer);
|
|
// procedure Print(AOscCustomers : IBizOscCustomer);
|
|
end;
|
|
|
|
implementation
|
|
|
|
uses
|
|
cxControls, DB, uEditorRegistryUtils,
|
|
uDAInterfaces, uDataTableUtils,
|
|
uDateUtils, uROTypes, DateUtils, Controls, Windows,
|
|
|
|
// Descomentar esto si hay informe
|
|
// uOscCustomersReportController,
|
|
|
|
schTiendaWebClient_Intf, uDataModuleTiendaWeb;
|
|
|
|
{ TOscCustomersController }
|
|
|
|
procedure TOscCustomersController.Anadir(AOscCustomers: IBizOscCustomer);
|
|
begin
|
|
AOscCustomers.Insert;
|
|
end;
|
|
|
|
procedure TOscCustomersController.AsignarDataModule;
|
|
begin
|
|
FDataModule := TDataModuleTiendaWeb.Create(Nil);
|
|
end;
|
|
|
|
procedure TOscCustomersController.AsignarID(AOscCustomers: IBizOscCustomer;
|
|
const IDNuevo: Integer);
|
|
begin
|
|
if not Assigned(AOscCustomers) then
|
|
raise Exception.Create ('OscCustomers no asignado');
|
|
|
|
// { Los detalles hay que comprobarlos siempre
|
|
// tanto en inserción como en modificación. }
|
|
if Assigned(AOscCustomers.AddressBook) then
|
|
FAddressBookController.AsignarID(AOscCustomers.AddressBook, IDNuevo, AOscCustomers.EsNuevo);
|
|
|
|
if AOscCustomers.EsNuevo then
|
|
begin
|
|
AOscCustomers.Edit;
|
|
AOscCustomers.customers_id := IDNuevo;
|
|
AOscCustomers.Post;
|
|
end;
|
|
end;
|
|
|
|
function TOscCustomersController.BuscarTodos: IBizOscCustomer;
|
|
begin
|
|
Result := FDataModule.GetOSCCustomers;
|
|
end;
|
|
|
|
constructor TOscCustomersController.Create;
|
|
begin
|
|
AsignarDataModule;
|
|
|
|
FAddressBookController := TOscAddressBookController.Create;
|
|
end;
|
|
|
|
function TOscCustomersController.Buscar(const IDLocal: Integer): IBizOscCustomer;
|
|
begin
|
|
Result := FDataModule.GetOSCCustomer(IDLocal);
|
|
end;
|
|
|
|
function TOscCustomersController._Vacio: IBizOscCustomer;
|
|
begin
|
|
Result := Buscar(ID_NULO);
|
|
end;
|
|
|
|
function TOscCustomersController.DarListaOscCustomers: TStringList;
|
|
{var
|
|
AOscCustomers: IBizOscCustomer;}
|
|
begin
|
|
{ AOscCustomers := BuscarTodos;
|
|
AOscCustomers.DataTable.Active := True;
|
|
Result := TStringList.Create;
|
|
try
|
|
with Result do
|
|
begin
|
|
AOscCustomers.DataTable.First;
|
|
while not AOscCustomers.DataTable.EOF do
|
|
begin
|
|
Add(AOscCustomers.DESCRIPCION);
|
|
AOscCustomers.DataTable.Next;
|
|
end;
|
|
end;
|
|
finally
|
|
AOscCustomers := NIL;
|
|
end;}
|
|
end;
|
|
|
|
procedure TOscCustomersController.DescartarCambios(AOscCustomers: IBizOscCustomer);
|
|
begin
|
|
if not Assigned(AOscCustomers) then
|
|
raise Exception.Create ('OscCustomers no asignado');
|
|
|
|
ShowHourglassCursor;
|
|
try
|
|
if (AOscCustomers.State in dsEditModes) then
|
|
AOscCustomers.Cancel;
|
|
|
|
AOscCustomers.DataTable.CancelUpdates;
|
|
finally
|
|
HideHourglassCursor;
|
|
end;
|
|
end;
|
|
|
|
destructor TOscCustomersController.Destroy;
|
|
begin
|
|
FDataModule := NIL;
|
|
FAddressBookController := NIL;
|
|
inherited;
|
|
end;
|
|
|
|
|
|
function TOscCustomersController.Duplicar(AOscCustomers: IBizOscCustomer): IBizOscCustomer;
|
|
begin
|
|
Result := Self._Vacio;
|
|
ShowHourglassCursor;
|
|
try
|
|
DuplicarRegistros(AOscCustomers.DataTable, Result.DataTable, mdrActual);
|
|
|
|
// Descomentar esto si hay detalles
|
|
// DuplicarRegistros(AOscCustomers.Detalles.DataTable, Result.Detalles.DataTable, mdrTodos);
|
|
|
|
// ¡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 TOscCustomersController.ValidarOscCustomers(AOscCustomers: IBizOscCustomer): Boolean;
|
|
begin
|
|
Result := False;
|
|
|
|
if not Assigned(AOscCustomers) then
|
|
raise Exception.Create ('OscCustomers no asignado');
|
|
|
|
if (AOscCustomers.DataTable.State in dsEditModes) then
|
|
AOscCustomers.DataTable.Post;
|
|
|
|
// Descomentar esto si hay detalles
|
|
// // Tambien hacemos post de sus tablas hija
|
|
// if (AOscCustomers.Detalles.DataTable.State in dsEditModes) then
|
|
// AOscCustomers.Detalles.DataTable.Post;
|
|
|
|
|
|
// Ejemplos de validaciones
|
|
{
|
|
if (AOscCustomers.ID_CLIENTE < 0) or
|
|
(not Assigned(AOscCustomers.Cliente)) or
|
|
(AOscCustomers.Cliente.IsEmpty) then
|
|
raise Exception.Create('Debe indicar el cliente de esta factura');
|
|
|
|
if (EsFechaVacia(AOscCustomers.FECHA_FACTURA)) then
|
|
raise Exception.Create('Debe indicar la fecha de esta factura');
|
|
|
|
if Length(AOscCustomers.REFERENCIA) = 0 then
|
|
raise Exception.Create('Debe indicar una referencia para esta forma de pago.');
|
|
|
|
if Length(AOscCustomers.DESCRIPCION) = 0 then
|
|
raise Exception.Create('Debe indicar una descripción para esta forma de pago.');
|
|
}
|
|
|
|
|
|
{ Asegurarse de valores en campos "automáticos" tanto
|
|
en MODIFICACIÓN como en INSERCIÓN. }
|
|
{ AOscCustomers.Edit;
|
|
try
|
|
AOscCustomers.USUARIO := dmUsuarios.LoginInfo.Usuario;
|
|
Result := True;
|
|
finally
|
|
AOscCustomers.Post;
|
|
end;}
|
|
|
|
Result := True;
|
|
end;
|
|
|
|
procedure TOscCustomersController.Ver(AOscCustomers: IBizOscCustomer);
|
|
{var
|
|
AEditor : IEditorOscCustomers;}
|
|
begin
|
|
{ AEditor := NIL;
|
|
ShowHourglassCursor;
|
|
try
|
|
CreateEditor('EditorOscCustomers', IEditorOscCustomers, AEditor);
|
|
with AEditor do
|
|
OscCustomers := AOscCustomers;
|
|
finally
|
|
HideHourglassCursor;
|
|
end;
|
|
|
|
if Assigned(AEditor) then
|
|
try
|
|
AEditor.ShowModal;
|
|
AEditor.Release;
|
|
finally
|
|
AEditor := NIL;
|
|
end;}
|
|
end;
|
|
|
|
procedure TOscCustomersController.VerTodos(AOscCustomers: IBizOscCustomer);
|
|
{var
|
|
AEditor : IEditorOscCustomers;}
|
|
begin
|
|
{ AEditor := NIL;
|
|
ShowHourglassCursor;
|
|
try
|
|
CreateEditor('EditorOscCustomers', IEditorOscCustomers, AEditor);
|
|
with AEditor do
|
|
OscCustomers := AOscCustomers;
|
|
finally
|
|
HideHourglassCursor;
|
|
end;
|
|
|
|
if Assigned(AEditor) then
|
|
try
|
|
AEditor.ShowModal;
|
|
AEditor.Release;
|
|
finally
|
|
AEditor := NIL;
|
|
end;}
|
|
end;
|
|
|
|
function TOscCustomersController.Eliminar(AOscCustomers: IBizOscCustomer): Boolean;
|
|
begin
|
|
Result := False;
|
|
|
|
if not Assigned(AOscCustomers) then
|
|
raise Exception.Create ('OscCustomers no asignado');
|
|
|
|
ShowHourglassCursor;
|
|
try
|
|
if (AOscCustomers.State in dsEditModes) then
|
|
AOscCustomers.Cancel;
|
|
|
|
AOscCustomers.Delete;
|
|
AOscCustomers.DataTable.ApplyUpdates;
|
|
HideHourglassCursor;
|
|
Result := True;
|
|
finally
|
|
HideHourglassCursor;
|
|
end;
|
|
end;
|
|
|
|
procedure TOscCustomersController.RecibirAviso(ASujeto: ISujeto; ADataTable: IDAStronglyTypedDataTable);
|
|
// Descomentar si hubiera detalles
|
|
{var
|
|
AOscCustomers : IBizOscCustomer;
|
|
ADetalles : IBizDetallesOscCustomers;}
|
|
begin
|
|
inherited;
|
|
|
|
// Descomentar si hubiera detalles
|
|
{if Supports(ADataTable, IBizDetallesOscCustomers, ADetalles) and
|
|
Supports(ADetalles.DataTable.MasterSource.DataTable, IBizOscCustomer, AOscCustomers) then
|
|
begin
|
|
AOscCustomers.Edit;
|
|
try
|
|
AOscCustomers.IMPORTE_TOTAL := FDetallesController.DarTotalImporteTotal(ADetalles);
|
|
finally
|
|
AOscCustomers.Post;
|
|
end;
|
|
end;}
|
|
end;
|
|
|
|
function TOscCustomersController.Guardar(AOscCustomers: IBizOscCustomer): Boolean;
|
|
var
|
|
NuevoID : Integer;
|
|
begin
|
|
Result := False;
|
|
|
|
if ValidarOscCustomers(AOscCustomers) then
|
|
begin
|
|
ShowHourglassCursor;
|
|
try
|
|
if AOscCustomers.EsNuevo then
|
|
NuevoID := FDataModule.GetNextIDOSC('customers')
|
|
else
|
|
NuevoID := AOscCustomers.customers_id;
|
|
|
|
AsignarID(AOscCustomers, NuevoID);
|
|
AOscCustomers.DataTable.ApplyUpdates;
|
|
|
|
Result := True;
|
|
finally
|
|
HideHourglassCursor;
|
|
end;
|
|
end;
|
|
end;
|
|
|
|
function TOscCustomersController.Localizar(AOscCustomers: IBizOscCustomer; AIDLocal: Integer): Boolean;
|
|
begin
|
|
Result := True;
|
|
ShowHourglassCursor;
|
|
try
|
|
with AOscCustomers.DataTable do
|
|
begin
|
|
DisableControls;
|
|
First;
|
|
if not Locate(fld_osc_Customersrdx_customers_id_local, AIDLocal, []) then
|
|
Result := False;
|
|
EnableControls;
|
|
end;
|
|
finally
|
|
HideHourglassCursor;
|
|
end;
|
|
end;
|
|
|
|
function TOscCustomersController.Nuevo: IBizOscCustomer;
|
|
var
|
|
AOSCCustomer : IBizOscCustomer;
|
|
begin
|
|
AOSCCustomer := (FDataModule as IDataModuleTiendaWeb).NewOSCCustomer;
|
|
AOSCCustomer.DataTable.Active := True;
|
|
AOSCCustomer.Insert;
|
|
Result := AOSCCustomer;
|
|
end;
|
|
|
|
function TOscCustomersController.ExtraerSeleccionados(AOscCustomers: IBizOscCustomer): IBizOscCustomer;
|
|
var
|
|
ASeleccionados : IBizOscCustomer;
|
|
begin
|
|
ASeleccionados := (Self.Buscar(ID_NULO) as IBizOscCustomer);
|
|
CopyDataTable(AOscCustomers.DataTable, ASeleccionados.DataTable, True);
|
|
Result := ASeleccionados;
|
|
end;
|
|
|
|
function TOscCustomersController.ElegirOscCustomers(AOscCustomers: IBizOscCustomer; AMensaje: String; AMultiSelect: Boolean): IBizOscCustomer;
|
|
{var
|
|
AEditor : IEditorElegirOscCustomers;}
|
|
begin
|
|
Result := NIL;
|
|
|
|
{ CreateEditor('EditorElegirOscCustomers', IEditorElegirOscCustomers, AEditor);
|
|
try
|
|
with AEditor do
|
|
begin
|
|
OscCustomers := AOscCustomers;
|
|
MultiSelect := AMultiSelect;
|
|
Mensaje := AMensaje;
|
|
if IsPositiveResult(ShowModal) then
|
|
Result := OscCustomersSeleccionados;
|
|
Release;
|
|
end;
|
|
finally
|
|
AEditor := NIL;
|
|
end;}
|
|
end;
|
|
|
|
// Descomentar esto si hay informe
|
|
// procedure TOscCustomersController.Preview(AOscCustomers: IBizOscCustomer);
|
|
// var
|
|
// AReportController : IOscCustomersReportController;
|
|
// begin
|
|
// AReportController := TOscCustomersReportController.Create;
|
|
// try
|
|
// AReportController.Preview(AOscCustomers.ID);
|
|
// finally
|
|
// AReportController := NIL;
|
|
// end;
|
|
// end;
|
|
|
|
// Descomentar esto si hay informe
|
|
// procedure TOscCustomersController.Print(AOscCustomers: IBizOscCustomer);
|
|
// var
|
|
// AReportController : IOscCustomersReportController;
|
|
// begin
|
|
// AReportController := TOscCustomersReportController.Create;
|
|
// try
|
|
// AReportController.Print(AOscCustomers.ID);
|
|
// finally
|
|
// AReportController := NIL;
|
|
// end;
|
|
// end;
|
|
|
|
end.
|