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/Presupuestos_/Cliente/uDataModulePresupuestos.pas

291 lines
9.5 KiB
ObjectPascal

unit uDataModulePresupuestos;
interface
uses {vcl:} SysUtils, Classes, DB, DBClient,
{RemObjects:} uDAClientDataModule, uDADataTable, uDABINAdapter,
uROServiceComponent, uRORemoteService, uROClient, uROBinMessage,
uROWinInetHttpChannel, uDAScriptingProvider, uDACDSDataTable,
uBizPresupuestosCliente, FactuGES_Intf,
frxExportImage, frxExportPDF, frxDCtrl,
frxClass, frxDMPExport, frxGradient, frxChBox, frxCross, frxRich,
frxChart, frxOLE, frxBarcode;
type
TdmPresupuestos = class(TDAClientDataModule)
RORemoteService: TRORemoteService;
DABinAdapter: TDABINAdapter;
tbl_DetallesPresupuestos: TDACDSDataTable;
ds_DetallesPresupuestos: TDADataSource;
tbl_Presupuestos: TDACDSDataTable;
ds_Presupuestos: TDADataSource;
procedure DAClientDataModuleCreate(Sender: TObject);
public
function DarNuevaReferencia (TipoPresupuesto : String) : String;
function PuedoEliminarPresupuesto (CodigoPresupuesto : Integer) : Boolean;
function GetReferencia (CodigoPresupuesto : Integer) : String;
function GetNextAutoinc : integer;
function GetPresupuestos: IBizPresupuestos;
function GetPresupuesto(CodigoPresupuesto : Integer) : IBizPresupuestos;
function GetPresupuestosSinAlbaran: IBizPresupuestos;
function GetPresupuestosSinMontaje: IBizPresupuestos;
function SetReferencia (APresupuesto: IBizPresupuestos; Referencia: Variant): Boolean;
procedure Preview(Const Codigo: Integer);
procedure Refrescar(lReport: TfrxReport; Const Codigo: Integer; const TamLetra: Integer);
procedure Print(Const Codigo: Integer);
function GetItemsSeleccionados(ASource : IBizPresupuestos): IBizPresupuestos;
end;
var
dmPresupuestos: TdmPresupuestos;
implementation
{$R *.DFM}
uses
Forms, Controls, uDataTableUtils, uBizContacto, Dialogs, Variants,
uDataModuleContactos, uDataModuleBase, schPresupuestosClient_Intf,
uDAInterfaces, uEditorPreview, uEditorPreviewPresupuesto, uROTypes, schPresupuestosServer_Intf,
uDBSelectionList;
function TdmPresupuestos.GetPresupuestos: IBizPresupuestos;
var
dtPresupuestos: TDACDSDataTable;
dtDetalles: TDACDSDataTable;
ACursor: TCursor;
begin
ACursor := Screen.Cursor;
Screen.Cursor := crHourGlass;
try
dtPresupuestos := TDACDSDataTable.Create(NIL);
CloneDataTable(tbl_Presupuestos, dtPresupuestos);
with dtPresupuestos do
begin
BusinessRulesID := BIZ_PRESUPUESTOCLIENTE;
FieldByName(fld_PresupuestosDESCUENTO).BusinessRulesID := 'Client.Field.Descuento';
FieldByName(fld_PresupuestosIVA).BusinessRulesID := 'Client.Field.IVA';
end;
dtDetalles := TDACDSDataTable.Create(NIL);
CloneDataTable(tbl_DetallesPresupuestos, dtDetalles);
with dtDetalles do
begin
BusinessRulesID := BIZ_DETALLESPRESUPUESTOCLIENTE;
DetailOptions := DetailOptions - [dtDisableLogOfCascadeDeletes, dtDisableLogOfCascadeUpdates];
FieldByName(fld_DetallesPresupuestosCANTIDAD).BusinessRulesID := 'Client.Field.Cantidad';
FieldByName(fld_DetallesPresupuestosIMPORTEUNIDAD).BusinessRulesID := 'Client.Field.ImporteUnidad';
FieldByName(fld_DetallesPresupuestosTIPO).BusinessRulesID := 'Client.Field.TipoDetalle';
FieldByName(fld_DetallesPresupuestosPUNTOS).BusinessRulesID := 'Client.Field.Puntos';
FieldByName(fld_DetallesPresupuestosIMPORTEPUNTOS).BusinessRulesID := 'Client.Field.ImportePuntos';
FieldByName(fld_DetallesPresupuestosVISIBLE).BusinessRulesID := 'Client.Field.Visible';
FieldByName(fld_DetallesPresupuestosVALORADO).BusinessRulesID := 'Client.Field.Valorado';
end;
(dtPresupuestos as IBizPresupuestos).Detalles := (dtDetalles as IBizDetallesPresupuesto);
Result := (dtPresupuestos as IBizPresupuestos);
finally
Screen.Cursor := ACursor;
end;
end;
procedure TdmPresupuestos.DAClientDataModuleCreate(Sender: TObject);
begin
RORemoteService.Channel := dmBase.Channel;
RORemoteService.Message := dmBase.Message;
Adapter := dmBase.Adapter;
end;
function TdmPresupuestos.GetPresupuestosSinAlbaran: IBizPresupuestos;
var
dsPresupuestos : IBizPresupuestos;
begin
dsPresupuestos := GetPresupuestos;
with dsPresupuestos.DataTable.Where do
begin
if not Empty then
AddOperator(opAND);
Clear;
OpenBraket;
AddText('ALBARANPAGO.CODIGO is null', False);
CloseBraket;
AddOperator(opAND);
OpenBraket;
AddText('PRESUPUESTOS.' + fld_PresupuestosSITUACION + '=' + '''' + SITUACION_ACEPTADO + '''', False);
CloseBraket;
AddOperator(opAND);
OpenBraket;
AddText('PRESUPUESTOS.' + fld_PresupuestosREFERENCIA + ' is not NULL', False);
CloseBraket;
end;
Result := dsPresupuestos;
end;
function TdmPresupuestos.GetNextAutoinc: integer;
begin
Result := (RORemoteService as IsrvPresupuestos).GetNextAutoinc;
end;
procedure TdmPresupuestos.Preview(Const Codigo: Integer);
var
AStream: TROBinaryMemoryStream;
AEditorPreviewPresupuesto : TfEditorPreviewPresupuesto;
begin
AEditorPreviewPresupuesto := TfEditorPreviewPresupuesto.Create(Application);
try
AStream := (RORemoteService as IsrvPresupuestos).GenerateReport(Codigo, 0);
AEditorPreviewPresupuesto.Report.PreviewPages.LoadFromStream(AStream);
AEditorPreviewPresupuesto.Codigo := Codigo;
AEditorPreviewPresupuesto.ShowModal;
finally
AEditorPreviewPresupuesto.Release;
AStream.Free;
end;
end;
function TdmPresupuestos.DarNuevaReferencia(TipoPresupuesto: String): String;
begin
Result := (RORemoteService as IsrvPresupuestos).DarNuevaReferencia(TipoPresupuesto);
end;
function TdmPresupuestos.GetReferencia(CodigoPresupuesto: Integer): String;
var
APresupuesto : IBizPresupuestos;
begin
APresupuesto := GetPresupuesto(CodigoPresupuesto);
APresupuesto.DataTable.Active := True;
Result := APresupuesto.REFERENCIA;
end;
function TdmPresupuestos.GetPresupuesto(
CodigoPresupuesto: Integer): IBizPresupuestos;
var
APresupuesto : IBizPresupuestos;
begin
APresupuesto := GetPresupuestos;
with APresupuesto.DataTable.Where do
AddText(fld_PresupuestosCODIGO + ' = ' + IntToStr(CodigoPresupuesto));
Result := APresupuesto;
end;
function TdmPresupuestos.PuedoEliminarPresupuesto(
CodigoPresupuesto: Integer): Boolean;
begin
Result := (RORemoteService as IsrvPresupuestos).PuedoEliminarPresupuesto(CodigoPresupuesto);
end;
procedure TdmPresupuestos.Print(const Codigo: Integer);
var
AStream: TROBinaryMemoryStream;
AEditorPreview : TfEditorPreview;
begin
AEditorPreview := TfEditorPreview.Create(Application);
try
AStream := (RORemoteService as IsrvPresupuestos).GenerateReport(Codigo, 0);
AEditorPreview.Report.PreviewPages.LoadFromStream(AStream);
AEditorPreview.Print;
finally
AEditorPreview.Release;
AStream.Free;
end;
end;
function TdmPresupuestos.GetPresupuestosSinMontaje: IBizPresupuestos;
var
dsPresupuestos : IBizPresupuestos;
begin
dsPresupuestos := GetPresupuestos;
with dsPresupuestos.DataTable.Where do
begin
if not Empty then
AddOperator(opAND);
Clear;
OpenBraket;
AddText('PRESUPUESTOS.' + fld_PresupuestosCODIGO + ' not in (select CODIGOPRESUPUESTO from MONTAJES where CODIGOEMPRESA = ' + IntToStr(dmBase.CodigoEmpresa) + ' and CODIGOPRESUPUESTO is not null)', False);
CloseBraket;
AddOperator(opAND);
OpenBraket;
AddText('PRESUPUESTOS.' + fld_PresupuestosSITUACION + '=' + '''' + SITUACION_ACEPTADO + '''', False);
CloseBraket;
{ AddOperator(opAND);
OpenBraket;
AddText('PRESUPUESTOS.' + fld_PresupuestosREFERENCIA + ' is not NULL', False);
CloseBraket;}
end;
Result := dsPresupuestos;
end;
function TdmPresupuestos.GetItemsSeleccionados(
ASource: IBizPresupuestos): IBizPresupuestos;
var
aObj : ISelectedRowList;
dtPresupuesto : IBizPresupuestos;
i : integer;
begin
if Supports(ASource, ISelectedRowList, aObj) then
begin
if (aObj.SelectedRows.Count = 1) then
begin
ASource.DataTable.GotoBookmark(aObj.SelectedRows[0]);
Result := GetPresupuesto(ASource.CODIGO);
Exit;
end
else
dtPresupuesto := GetPresupuestos;
end
else
raise Exception.Create('Interface no soportada (GetItemsSeleccionados)');
if dtPresupuesto.DataTable.Active then
dtPresupuesto.DataTable.Active := False;
with dtPresupuesto.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);
AddText('PRESUPUESTOS.' + fld_PresupuestosCODIGO + ' = ' + IntToStr(ASource.CODIGO));
end;
end;
Result := dtPresupuesto;
end;
function TdmPresupuestos.SetReferencia(APresupuesto: IBizPresupuestos; Referencia: Variant): Boolean;
begin
Result:= False;
try
if not (APresupuesto.DataTable.State in dsEditModes) then
APresupuesto.DataTable.Edit;
APresupuesto.DataTable.FieldByName(fld_PresupuestosREFERENCIA).AsVariant := Referencia;
APresupuesto.Post;
Result:= True;
except
end;
end;
procedure TdmPresupuestos.Refrescar(lReport: TfrxReport; Const Codigo: Integer; const TamLetra: Integer);
var
AStream: TROBinaryMemoryStream;
begin
AStream := (RORemoteService as IsrvPresupuestos).GenerateReport(Codigo, TamLetra);
lReport.PreviewPages.LoadFromStream(AStream);
lReport.ShowPreparedReport;
end;
initialization
dmPresupuestos := TdmPresupuestos.Create(nil);
finalization
FreeAndNil(dmPresupuestos);
end.