git-svn-id: https://192.168.0.254/svn/Proyectos.LuisLeon_FactuGES/trunk@327 c93665c3-c93d-084d-9b98-7d5f4a9c3376
216 lines
6.3 KiB
ObjectPascal
216 lines
6.3 KiB
ObjectPascal
unit uDataModuleFacturasCliente;
|
||
|
||
interface
|
||
|
||
uses
|
||
SysUtils, Classes, DB, uDAClientDataModule, uDADataTable, uDABINAdapter,
|
||
uDAScriptingProvider, uDACDSDataTable, uROWinInetHttpChannel, uROTypes,
|
||
uROServiceComponent, uRORemoteService, uROClient, uROBinMessage,
|
||
|
||
uIDataModuleFacturasCliente, uBizFacturasCliente, uBizDetallesFacturaCliente,
|
||
uDADesigntimeCall, uIDataModuleFacturasClienteReport, uIntegerListUtils;
|
||
|
||
type
|
||
TDataModuleFacturasCliente = class(TDAClientDataModule, IDataModuleFacturasCliente, IDataModuleFacturasClienteReport)
|
||
RORemoteService: TRORemoteService;
|
||
DABinAdapter: TDABINAdapter;
|
||
tbl_FacturasCliente: TDACDSDataTable;
|
||
ds_FacturasCliente: TDADataSource;
|
||
tbl_FacturasCliente_Detalles: TDACDSDataTable;
|
||
ds_FacturasCliente_Detalles: TDADataSource;
|
||
DADesigntimeCall1: TDADesigntimeCall;
|
||
LoginRemoteService: TRORemoteService;
|
||
ROWinInetHTTPChannel1: TROWinInetHTTPChannel;
|
||
ROBinMessage1: TROBinMessage;
|
||
tbl_ListaAnosFacturas: TDACDSDataTable;
|
||
ds_ListaAnosFacturas: TDADataSource;
|
||
procedure DAClientDataModuleCreate(Sender: TObject);
|
||
private
|
||
function _CloneDataTable (const ADataTable : TDACDSDataTable): TDACDSDataTable; overload;
|
||
function _GetDetalles : IBizDetallesFacturaCliente;
|
||
public
|
||
function GetAnosItems : TStringList;
|
||
function GetItems : IBizFacturaCliente;
|
||
function GetItem(const ID : Integer) : IBizFacturaCliente;
|
||
function GetNextID(const DataSetName : String) : Integer;
|
||
function NewItem : IBizFacturaCliente;
|
||
|
||
// Report
|
||
function GetRptFacturas(const AListaID: TIntegerList;
|
||
const ShowLogotipo: Boolean = False): Binary;
|
||
function GetRptPDFFacturas(const AID: Integer;
|
||
const ShowLogotipo: Boolean = False): Binary;
|
||
end;
|
||
|
||
implementation
|
||
|
||
{$R *.DFM}
|
||
|
||
uses
|
||
Forms, Windows, FactuGES_Intf, uDataModuleConexion, uDataTableUtils, cxControls,
|
||
uDAInterfaces, schFacturasClienteClient_Intf, uBizContactos;
|
||
|
||
{ TdmPresupuestos }
|
||
|
||
procedure TDataModuleFacturasCliente.DAClientDataModuleCreate(Sender: TObject);
|
||
begin
|
||
RORemoteService.Channel := dmConexion.Channel;
|
||
RORemoteService.Message := dmConexion.Message;
|
||
end;
|
||
|
||
function TDataModuleFacturasCliente.GetNextID(const DataSetName: String): Integer;
|
||
var
|
||
aGeneratorName : String;
|
||
begin
|
||
if DataSetName = nme_FacturasCliente then
|
||
aGeneratorName := 'GEN_FACTURAS_CLIENTE_ID';
|
||
|
||
if DataSetName = nme_FacturasCliente_Detalles then
|
||
aGeneratorName := 'GEN_FACTURA_CLIENTE_DETALLES_ID';
|
||
|
||
Result := (RORemoteService as IsrvFacturasCliente).GetNextAutoInc(aGeneratorName)
|
||
end;
|
||
|
||
function TDataModuleFacturasCliente.GetRptPDFFacturas(
|
||
const AID: Integer; const ShowLogotipo: Boolean = False): Binary;
|
||
var
|
||
AParam : TIntegerArray;
|
||
Tipo: Integer;
|
||
begin
|
||
//Si dice que no se imprimir<69> la factura como becoaching
|
||
Tipo := 1;
|
||
if (Application.MessageBox('<27>Desea imprimir las facturas/abonos de cliente seleccionados, con el modelo por defecto?', 'Atenci<63>n', MB_YESNO) = IDNO) then
|
||
Tipo := 2;
|
||
|
||
AParam := TIntegerArray.Create;
|
||
try
|
||
AParam.Add(AID);
|
||
Result := (RORemoteService as IsrvFacturasCliente).GenerarInformeEnPDF(AParam, ShowLogotipo, Tipo)
|
||
finally
|
||
FreeANDNIL(AParam)
|
||
end;
|
||
end;
|
||
|
||
function TDataModuleFacturasCliente.GetRptFacturas(
|
||
const AListaID: TIntegerList; const ShowLogotipo: Boolean = False): Binary;
|
||
var
|
||
AParam : TIntegerArray;
|
||
Tipo: Integer;
|
||
begin
|
||
//Si dice que no se imprimir<69> la factura como becoaching
|
||
Tipo := 1;
|
||
if (Application.MessageBox('<27>Desea imprimir las facturas/abonos de cliente seleccionados, con el modelo por defecto?', 'Atenci<63>n', MB_YESNO) = IDNO) then
|
||
Tipo := 2;
|
||
|
||
AParam := AListaID.ToIntegerArray;
|
||
try
|
||
Result := (RORemoteService as IsrvFacturasCliente).GenerarInforme(AParam, ShowLogotipo, Tipo)
|
||
finally
|
||
FreeANDNIL(AParam)
|
||
end;
|
||
end;
|
||
|
||
function TDataModuleFacturasCliente.NewItem: IBizFacturaCliente;
|
||
begin
|
||
Result := GetItem(ID_NULO)
|
||
end;
|
||
|
||
function TDataModuleFacturasCliente._CloneDataTable(const ADataTable : TDACDSDataTable): TDACDSDataTable;
|
||
begin
|
||
Result := NIL;
|
||
|
||
if not Assigned(ADataTable) then
|
||
raise Exception.Create ('No se ha asignado la tabla de origen (CloneDataTable)');
|
||
|
||
Result := TDACDSDataTable.Create(NIL);
|
||
CloneDataTable(ADataTable, Result);
|
||
end;
|
||
|
||
function TDataModuleFacturasCliente._GetDetalles: IBizDetallesFacturaCliente;
|
||
var
|
||
ADetalles : TDACDSDataTable;
|
||
begin
|
||
ShowHourglassCursor;
|
||
try
|
||
ADetalles := _CloneDataTable(tbl_FacturasCliente_Detalles);
|
||
with ADetalles do
|
||
begin
|
||
BusinessRulesID := BIZ_CLIENT_DETALLES_FACTURA_CLIENTE;
|
||
DetailOptions := DetailOptions -
|
||
[dtDisableLogOfCascadeDeletes, dtDisableLogOfCascadeUpdates];
|
||
end;
|
||
Result := (ADetalles as IBizDetallesFacturaCliente);
|
||
finally
|
||
HideHourglassCursor;
|
||
end;
|
||
end;
|
||
|
||
function TDataModuleFacturasCliente.GetAnosItems: TStringList;
|
||
var
|
||
AListaAnos: TStringList;
|
||
begin
|
||
AListaAnos := TStringList.Create;
|
||
ShowHourglassCursor;
|
||
try
|
||
with tbl_ListaAnosFacturas 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;
|
||
|
||
function TDataModuleFacturasCliente.GetItem(const ID: Integer): IBizFacturaCliente;
|
||
begin
|
||
ShowHourglassCursor;
|
||
try
|
||
Result := Self.GetItems;
|
||
with Result.DataTable.Where do
|
||
begin
|
||
if NotEmpty then
|
||
AddOperator(opAND);
|
||
OpenBraket;
|
||
AddText(fld_FacturasClienteID + ' = ' + IntToStr(ID));
|
||
CloseBraket;
|
||
end;
|
||
finally
|
||
HideHourglassCursor;
|
||
end;
|
||
end;
|
||
|
||
function TDataModuleFacturasCliente.GetItems: IBizFacturaCliente;
|
||
var
|
||
AFactura : TDACDSDataTable;
|
||
begin
|
||
ShowHourglassCursor;
|
||
try
|
||
AFactura := _CloneDataTable(tbl_FacturasCliente);
|
||
|
||
// EL CAMPO REFERENCIA TIENE QUE SER AUTOREFRESH!!!!!
|
||
AFactura.FieldByName(fld_FacturasClienteREFERENCIA).ServerAutoRefresh := TRUE;
|
||
|
||
AFactura.BusinessRulesID := BIZ_CLIENT_FACTURA_CLIENTE;
|
||
|
||
with TBizFacturaCliente(AFactura.BusinessEventsObj) do
|
||
begin
|
||
Detalles := _GetDetalles;
|
||
end;
|
||
|
||
Result := (AFactura as IBizFacturaCliente);
|
||
finally
|
||
HideHourglassCursor;
|
||
end;
|
||
end;
|
||
|
||
|
||
end.
|