This repository has been archived on 2024-12-02. You can view files and clone it, but cannot push or open issues or pull requests.
AlonsoYSal_FactuGES/Modulos/Montajes/Cliente/uDataModuleMontajes.pas

434 lines
13 KiB
ObjectPascal
Raw Blame History

unit uDataModuleMontajes;
interface
uses {vcl:} SysUtils, Classes, DB, DBClient,
{RemObjects:} uDAClientDataModule, uDADataTable, uDABINAdapter,
uROServiceComponent, uRORemoteService, uROClient, uROBinMessage,
uROWinInetHttpChannel, uDAScriptingProvider, uDACDSDataTable,
uBizMontajes, uBizPresupuestosCliente, schMontajesClient_Intf;
type
TdmMontajes = class(TDAClientDataModule)
DABINAdapter: TDABINAdapter;
RORemoteService: TRORemoteService;
tbl_Montajes: TDACDSDataTable;
ds_Montajes: TDADataSource;
tbl_FichaBeneficios: TDACDSDataTable;
ds_FichaBeneficios: TDADataSource;
tbl_FichaBeneficios_Aux: TDACDSDataTable;
ds_FichaBeneficios_Aux: TDADataSource;
tbl_ListaAnosMontajes: TDACDSDataTable;
ds_ListaAnosMontajes: TDADataSource;
procedure DAClientDataModuleCreate(Sender: TObject);
public
function GetItems: IBizMontaje; overload;
function GetItemsPendientes(Situacion: TEnumSituacion): IBizMontaje;
function GetItemsSeleccionados(ASource : IBizMontaje): IBizMontaje;
function GetItem(Codigo : Integer): IBizMontaje;
function GetItems(CodigoPresupuesto : Integer): IBizMontaje; overload;
function GetNextAutoinc(const Generador: String): integer;
procedure PreviewFicha(const Codigo:Integer);
procedure PrintFicha(const Codigo:Integer);
procedure PreviewEtiquetas(const Codigo : Integer; const NumEtiquetas : Integer);
procedure PrintEtiquetas(const Codigo : Integer; const NumEtiquetas : Integer);
function PuedoEliminarMontaje(Codigo : Integer) : Boolean;
function darFichaBeneficiosAux(const Tipo: String): IFichaBeneficios_Aux;
procedure NuevoMontaje(AMontaje: IBizMontaje; APresupuesto: IBizPresupuestos);
function CambiarSituacion(CodigoPresupuesto: Integer; Situacion: TEnumSituacion): String;
function DarNuevaReferencia (TipoMontaje : String) : String;
function DarListaAnosMontajes: TStringList;
procedure FiltrarAno(AMontajes: IBizMontaje; AWhereDataTable: String; const Ano: String);
end;
var
dmMontajes: TdmMontajes;
implementation
{$R *.DFM}
uses
Controls, cxControls, Forms, uDAInterfaces, DataAbstract_Intf, FactuGES_Intf,
uDataTableUtils, uROTypes, uEditorPreview,
Dialogs, uDataModuleBase, uDBSelectionList,
uDataModuleContactos, uDataModulePresupuestos;
const
MAX_RECORDS = 100;
procedure TdmMontajes.DAClientDataModuleCreate(Sender: TObject);
begin
RORemoteService.Channel := dmBase.Channel;
RORemoteService.Message := dmBase.Message;
end;
function TdmMontajes.GetItems: IBizMontaje;
var
dtMontajes: TDACDSDataTable;
dtFichaBeneficiosMontaje: TDACDSDataTable;
ACursor: TCursor;
begin
ACursor := Screen.Cursor;
Screen.Cursor := crHourGlass;
try
dtMontajes := TDACDSDataTable.Create(NIL);
CloneDataTable(tbl_Montajes, dtMontajes);
dtMontajes.BusinessRulesID := 'BizMontaje';
dtFichaBeneficiosMontaje := TDACDSDataTable.Create(NIL);
CloneDataTable(tbl_FichaBeneficios, dtFichaBeneficiosMontaje);
with dtFichaBeneficiosMontaje do
begin
BusinessRulesID := 'BizFichaBeneficiosMontaje';
DetailOptions := DetailOptions - [dtDisableLogOfCascadeDeletes, dtDisableLogOfCascadeUpdates];
end;
(dtMontajes as IBizMontaje).FichaBeneficios := (dtFichaBeneficiosMontaje as IBizFichaBeneficiosMontaje);
Result := (dtMontajes as IBizMontaje);
finally
Screen.Cursor := ACursor;
end;
end;
{function TdmAlmacenes.GetCliente(Codigo: Integer): IBizCliente;
var
// dtContactos: TDACDSDataTable;
// dtCategorias: TDACDSDataTable;
// ACursor: TCursor;
begin
{ ACursor := Screen.Cursor;
Screen.Cursor := crHourGlass;
try
dtContactos := TDACDSDataTable.Create(NIL);
CloneDataTable(tbl_Contactos, dtContactos);
dtContactos.BusinessRulesID := 'BizCliente';
dtCategorias := TDACDSDataTable.Create(NIL);
CloneDataTable(tbl_CategoriasContacto, dtCategorias);
dtCategorias.BusinessRulesID := 'BizCategoria';
(dtContactos as IBizContacto).Categorias := (dtCategorias as IBizCategoriasContacto);
Result := (dtContactos as IBizCliente);
GetCliente(Result, Codigo);
finally
Screen.Cursor := ACursor;
end;
end;
}
function TdmMontajes.GetItem(Codigo: Integer): IBizMontaje;
var
AMontaje: IBizMontaje;
begin
AMontaje := GetItems;
with AMontaje.DataTable do
begin
if Active then
Active := False;
Where.Clear;
Where.OpenBraket;
Where.AddText('MON.' + fld_MONTAJESCODIGO + ' = ' + IntToStr(Codigo), False);
Where.CloseBraket;
end;
Result := AMontaje;
end;
function TdmMontajes.GetNextAutoinc(const Generador: String): integer;
begin
Result := (RORemoteService as IsrvMontajes).GetNextAutoinc(Generador);
end;
function TdmMontajes.GetItemsSeleccionados(ASource: IBizMontaje): IBizMontaje;
var
aObj : ISelectedRowList;
dtMontaje : IBizMontaje;
i : integer;
begin
if Supports(ASource, ISelectedRowList, aObj) then
begin
if (aObj.SelectedRows.Count = 1) then
begin
ASource.DataTable.GotoBookmark(aObj.SelectedRows[0]);
Result := GetItem(ASource.CODIGO);
Exit;
end
else
dtMontaje := GetItems;
end
else
raise Exception.Create('Interface no soportada (GetItemsSeleccionados)');
if dtMontaje.DataTable.Active then
dtMontaje.DataTable.Active := False;
with dtMontaje.DataTable.Where do
begin
Clear;
for i := 0 to aObj.SelectedRows.Count - 1 do
begin
ASource.DataTable.GotoBookmark(aObj.SelectedRows[i]);
if i > 0 then
AddOperator(opAND);
AddCondition(fld_MontajesCODIGO, cEqual, ASource.CODIGO);
end;
end;
Result := dtMontaje;
end;
function TdmMontajes.GetItemsPendientes(Situacion: TEnumSituacion): IBizMontaje;
var
dsMontajes : IBizMontaje;
begin
dsMontajes := GetItems;
with dsMontajes.DataTable.Where do
begin
if not Empty then
AddOperator(opAND);
Clear;
OpenBraket;
case Situacion of
sitPendientes: begin
AddText('MONTAJES.' + fld_MontajesSITUACION + '=' + '''' + SITUACION_PENDIENTERECEPCION + '''', False);
AddText('OR MONTAJES.' + fld_MontajesSITUACION + '=' + '''' + SITUACION_PENDIENTEMONTAJE + '''', False);
AddText('OR MONTAJES.' + fld_MontajesSITUACION + '=' + '''' + SITUACION_PENDIENTEPAGO + '''', False);
end;
sitPendienteRecepcion: AddText('MONTAJES.' + fld_MontajesSITUACION + '=' + '''' + SITUACION_PENDIENTERECEPCION + '''', False);
sitPendienteMontaje: AddText('MONTAJES.' + fld_MontajesSITUACION + '=' + '''' + SITUACION_PENDIENTEMONTAJE + '''', False);
sitPendientePago: AddText('MONTAJES.' + fld_MontajesSITUACION + '=' + '''' + SITUACION_PENDIENTEPAGO + '''', False);
sitPagado: AddText('MONTAJES.' + fld_MontajesSITUACION + '=' + '''' + SITUACION_PAGADO + '''', False);
end;
CloseBraket;
end;
Result := dsMontajes;
end;
function TdmMontajes.PuedoEliminarMontaje(Codigo: Integer): Boolean;
begin
Result := (RORemoteService as IsrvMontajes).PuedoEliminarMontaje(Codigo);
end;
procedure TdmMontajes.PreviewFicha(Const Codigo:Integer);
var
AStream: TMemoryStream;
AEditorPreview : TfEditorPreview;
begin
AStream := Binary.Create;
AEditorPreview := TfEditorPreview.Create(Application);
try
AStream := (RemoteService as ISrvMontajes).GenerateReportFicha(Codigo);
AEditorPreview.Report.PreviewPages.LoadFromStream(AStream);
AEditorPreview.ShowModal;
finally
AEditorPreview.Release;
AStream.Free;
end;
end;
procedure TdmMontajes.PrintFicha(Const Codigo:Integer);
var
AStream: TMemoryStream;
AEditorPreview : TfEditorPreview;
begin
AStream := Binary.Create;
AEditorPreview := TfEditorPreview.Create(Application);
try
AStream := (RemoteService as ISrvMontajes).GenerateReportFicha(Codigo);
AEditorPreview.Report.PreviewPages.LoadFromStream(AStream);
AEditorPreview.Print;
finally
AEditorPreview.Release;
AStream.Free;
end;
end;
procedure TdmMontajes.PreviewEtiquetas(const Codigo : Integer;
const NumEtiquetas : Integer);
var
AStream: TMemoryStream;
AEditorPreview : TfEditorPreview;
begin
AStream := Binary.Create;
AEditorPreview := TfEditorPreview.Create(Application);
try
AStream := (RemoteService as ISrvMontajes).GenerateReportEtiquetas(Codigo, NumEtiquetas);
AEditorPreview.Report.PreviewPages.LoadFromStream(AStream);
AEditorPreview.ShowModal;
finally
AEditorPreview.Release;
AStream.Free;
end;
end;
procedure TdmMontajes.PrintEtiquetas(const Codigo : Integer;
const NumEtiquetas : Integer);
var
AStream: TMemoryStream;
AEditorPreview : TfEditorPreview;
begin
AStream := Binary.Create;
AEditorPreview := TfEditorPreview.Create(Application);
try
AStream := (RemoteService as ISrvMontajes).GenerateReportEtiquetas(Codigo, NumEtiquetas);
AEditorPreview.Report.PreviewPages.LoadFromStream(AStream);
AEditorPreview.Print;
finally
AEditorPreview.Release;
AStream.Free;
end;
end;
procedure TdmMontajes.NuevoMontaje(AMontaje: IBizMontaje; APresupuesto: IBizPresupuestos);
begin
if not Assigned(AMontaje) then
begin
AMontaje := getItem(-1);
AMontaje.DataTable.Active := True;
end;
//Siempre antes de la inserci<63>n que en el onnew de la clase de negocio se sepa que tipo de montaje ser<65>
//y poder generar la ficha de beneficios correspondiente
AMontaje.TipoFichaBeneficios := APresupuesto.TIPO;
AMontaje.Insert;
AMontaje.Presupuesto := APresupuesto;
AMontaje.Post;
AMontaje.DataTable.ApplyUpdates;
// if not AnadirFichaBeneficios(AMontaje.CODIGO) then
// raise Exception.Create('Error al crear ficha de beneficios');
end;
function TdmMontajes.darFichaBeneficiosAux(const Tipo: String): IFichaBeneficios_Aux;
var
dtFichaBeneficiosAux: TDACDSDataTable;
ACursor: TCursor;
begin
ACursor := Screen.Cursor;
Screen.Cursor := crHourGlass;
try
dtFichaBeneficiosAux := TDACDSDataTable.Create(NIL);
CloneDataTable(tbl_FichaBeneficios_Aux, dtFichaBeneficiosAux);
dtFichaBeneficiosAux.BusinessRulesID := 'BizFichaBeneficiosAux';
dtFichaBeneficiosAux.ParamByName('TIPO').AsString := Tipo;
Result := (dtFichaBeneficiosAux as IFichaBeneficios_Aux);
finally
Screen.Cursor := ACursor;
end;
end;
function TdmMontajes.CambiarSituacion(CodigoPresupuesto: Integer; Situacion: TEnumSituacion): String;
var
AMontaje: IBizMontaje;
begin
Result := '';
AMontaje := GetItems(CodigoPresupuesto);
AMontaje.DataTable.Active := True;
AMontaje.DataTable.First;
while not AMontaje.DataTable.EOF do
begin
AMontaje.DataTable.Edit;
Case Situacion of
sitPendientes: AMontaje.SITUACION := SITUACION_PENDIENTE;
sitPendienteRecepcion: AMontaje.SITUACION := SITUACION_PENDIENTERECEPCION;
sitPendienteMontaje: AMontaje.SITUACION := SITUACION_PENDIENTEMONTAJE;
sitPendientePago: AMontaje.SITUACION := SITUACION_PENDIENTEPAGO;
sitPagado: AMontaje.SITUACION := SITUACION_PAGADO;
end;
if (Length(Result) > 0) then
Result := Result + ', ';
Result := Result + AMontaje.REFERENCIA;
AMontaje.DataTable.Post;
AMontaje.DataTable.Next;
end;
//Solo si se han hecho cambios
if (Length(Result) > 0) then
AMontaje.DataTable.ApplyUpdates;
end;
function TdmMontajes.GetItems(CodigoPresupuesto: Integer): IBizMontaje;
var
AMontaje: IBizMontaje;
begin
AMontaje := GetItems;
with AMontaje.DataTable do
begin
if Active then
Active := False;
Where.Clear;
Where.OpenBraket;
Where.AddText('MON.' + fld_MONTAJESCODIGOPRESUPUESTO + ' = ' + IntToStr(CodigoPresupuesto), False);
Where.CloseBraket;
end;
Result := AMontaje;
end;
function TdmMontajes.DarNuevaReferencia(TipoMontaje: String): String;
begin
Result := (RORemoteService as IsrvMontajes).DarNuevaReferencia(TipoMontaje);
end;
function TdmMontajes.DarListaAnosMontajes: TStringList;
var
AListaAnos: TStringList;
begin
AListaAnos := TStringList.Create;
ShowHourglassCursor;
try
with tbl_ListaAnosMontajes do
begin
Open;
First;
while not eof do
begin
AListaAnos.Add(Format('%s=%s', [Fields[0].AsString, Fields[0].AsString]));
Next;
end;
Close;
end;
Result := AListaAnos;
finally
HideHourglassCursor;
end;
end;
procedure TdmMontajes.FiltrarAno(AMontajes: IBizMontaje; AWhereDataTable: String; const Ano: String);
var
FechaIni: String;
FechaFin: String;
begin
AMontajes.DataTable.Where.Clear;
AMontajes.DataTable.Where.AddText(AWhereDataTable);
if (Ano <> 'Todos') then
begin
// Filtrar los presupuestos actuales por a<>os
FechaIni := '01.01.' + Ano;
FechaFin := '31.12.' + Ano;
with AMontajes.DataTable.Where do
begin
if NotEmpty then
AddOperator(opAND);
AddCondition(fld_MontajesFECHAINICIO, cMajorOrEqual, FechaIni);
AddOperator(opAND);
AddCondition(fld_MontajesFECHAINICIO, cLessOrEqual, FechaFin);
end;
end;
end;
initialization
dmMontajes := TdmMontajes.Create(nil);
finalization
FreeAndNil(dmMontajes);
end.