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

385 lines
13 KiB
ObjectPascal

{
===============================================================================
Copyright (©) 2006. 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: 01-01-2006
Versión actual: 1.0.1
Fecha versión actual: 26-09-2006
===============================================================================
Modificaciones:
Fecha Comentarios
---------------------------------------------------------------------------
26-09-2006 Se ha modificado la lógica al seleccionar un presupuesto para
generar un albarán, ahora un albarán se podrá generar a partir
de un presupuesto aunque no tenga asignado ningún montaje
07-10-2007 PETICION DE RAQUEL - Así podrán crear montajes de presupuestos
que todavia no estan aceptados el proceso deberá cambiar de
situación el presupuesto elegido (SetReferencia, GetPresupuestosSinMontaje)
===============================================================================
}
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;
tbl_ListaAnosPresupuestos: TDACDSDataTable;
ds_ListaAnosPresupuestos: TDADataSource;
procedure DAClientDataModuleCreate(Sender: TObject);
public
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;
function DarListaAnosPresupuestos: TStringList;
procedure FiltrarAno(APresupuestos: IBizPresupuestos; AWhereDataTable: String; const Ano: String);
end;
var
dmPresupuestos: TdmPresupuestos;
implementation
{$R *.DFM}
uses
Forms, Controls, cxControls, uDataTableUtils, uBizContacto, Dialogs, Variants,
uDataModuleContactos, uDataModuleBase, schPresupuestosClient_Intf,
uDAInterfaces, uEditorPreview, uEditorPreviewPresupuesto, uROTypes,
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(fld_PresupuestosCODIGOALBARAN + ' is null', False);
CloseBraket;
AddOperator(opAND);
OpenBraket;
AddText(fld_PresupuestosSITUACION + '=' + '''' + SITUACION_ACEPTADO + '''', False);
CloseBraket;
// 26-09-2006
//
// 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.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(fld_PresupuestosCODIGO + ' not in (select CODIGOPRESUPUESTO from MONTAJES where CODIGOEMPRESA = ' + IntToStr(dmBase.CodigoEmpresa) + ' and CODIGOPRESUPUESTO is not null)', False);
CloseBraket;
//Así podrán crear montajes de presupuestos que todavia no estan aceptados
//el proceso deberá cambiar de situación el presupuesto elegido
// AddOperator(opAND);
// OpenBraket;
// AddText(fld_PresupuestosSITUACION + '=' + '''' + SITUACION_ACEPTADO + '''', False);
// CloseBraket;
{ AddOperator(opAND);
OpenBraket;
AddText(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(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;
//Si el presupuesto al que se la asigna la nueva referencia del montaje esta pendiente lo
//pasamos a aceptado
if not VarIsNull(Referencia)
and (APresupuesto.DataTable.FieldByName(fld_PresupuestosSITUACION).AsString = SITUACION_PENDIENTE) then
APresupuesto.DataTable.FieldByName(fld_PresupuestosSITUACION).AsString := SITUACION_ACEPTADO;
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;
procedure TdmPresupuestos.FiltrarAno(APresupuestos: IBizPresupuestos; AWhereDataTable: String; const Ano: String);
var
FechaIni: String;
FechaFin: String;
begin
APresupuestos.DataTable.Where.Clear;
APresupuestos.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 APresupuestos.DataTable.Where do
begin
if NotEmpty then
AddOperator(opAND);
AddCondition(fld_PresupuestosFECHAPRESUPUESTO, cMajorOrEqual, FechaIni);
AddOperator(opAND);
AddCondition(fld_PresupuestosFECHAPRESUPUESTO, cLessOrEqual, FechaFin);
end;
end;
end;
function TdmPresupuestos.DarListaAnosPresupuestos: TStringList;
var
AListaAnos: TStringList;
begin
AListaAnos := TStringList.Create;
ShowHourglassCursor;
try
with tbl_ListaAnosPresupuestos 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;
initialization
dmPresupuestos := TdmPresupuestos.Create(nil);
finalization
FreeAndNil(dmPresupuestos);
end.