2007-06-21 16:02:50 +00:00
|
|
|
|
unit uDataModuleFacturasCliente;
|
|
|
|
|
|
|
|
|
|
|
|
interface
|
|
|
|
|
|
|
|
|
|
|
|
uses {vcl:} SysUtils, Classes, DB, DBClient,
|
|
|
|
|
|
{RemObjects:} uDAClientDataModule, uDADataTable, uDABINAdapter,
|
|
|
|
|
|
uROServiceComponent, uRORemoteService, uROClient, uROBinMessage,
|
|
|
|
|
|
uROWinInetHttpChannel, uDAScriptingProvider, uDACDSDataTable,
|
|
|
|
|
|
uDADesigntimeCall, uBizFacturasCliente,
|
|
|
|
|
|
|
|
|
|
|
|
frxExportImage, frxExportPDF, frxDCtrl,
|
|
|
|
|
|
frxClass, frxDMPExport, frxGradient, frxChBox, frxCross, frxRich,
|
|
|
|
|
|
frxChart, frxOLE, frxBarcode;
|
|
|
|
|
|
|
|
|
|
|
|
type
|
|
|
|
|
|
TdmFacturasCliente = class(TDAClientDataModule)
|
|
|
|
|
|
RORemoteService: TRORemoteService;
|
|
|
|
|
|
tbl_FacturasCliente: TDACDSDataTable;
|
|
|
|
|
|
ds_FacturasCliente: TDADataSource;
|
|
|
|
|
|
tbl_DetallesFacturasCliente: TDACDSDataTable;
|
|
|
|
|
|
ds_DetallesFacturasCliente: TDADataSource;
|
|
|
|
|
|
DADesigntimeCall1: TDADesigntimeCall;
|
|
|
|
|
|
RORemoteService2: TRORemoteService;
|
2009-03-05 18:57:06 +00:00
|
|
|
|
tbl_ListaAnosFacturas: TDACDSDataTable;
|
|
|
|
|
|
ds_ListaAnosFacturas: TDADataSource;
|
2007-06-21 16:02:50 +00:00
|
|
|
|
procedure DAClientDataModuleCreate(Sender: TObject);
|
|
|
|
|
|
private
|
|
|
|
|
|
{ Private declarations }
|
|
|
|
|
|
public
|
|
|
|
|
|
function GetNextAutoinc : integer;
|
|
|
|
|
|
function GetItem: IBizFacturasCliente;
|
|
|
|
|
|
function GetItems: IBizFacturasCliente;
|
|
|
|
|
|
procedure Print(Const Codigo: Integer);
|
|
|
|
|
|
procedure Preview(Const Codigo: Integer);
|
|
|
|
|
|
function DarNuevaReferencia : String;
|
|
|
|
|
|
function PuedoEliminarFactura (CodigoFactura : Integer) : Boolean;
|
2009-03-05 18:57:06 +00:00
|
|
|
|
procedure Refrescar(lReport: TfrxReport; Const Codigo: Integer; const TamLetra: Integer);
|
|
|
|
|
|
|
|
|
|
|
|
function DarListaAnosFacturas: TStringList;
|
|
|
|
|
|
procedure FiltrarAno(AFacturas: IBizFacturasCliente; AWhereDataTable: String; const Ano: String);
|
2007-06-21 16:02:50 +00:00
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
|
|
var
|
|
|
|
|
|
dmFacturasCliente: TdmFacturasCliente;
|
|
|
|
|
|
|
|
|
|
|
|
implementation
|
|
|
|
|
|
|
|
|
|
|
|
{$R *.DFM}
|
|
|
|
|
|
|
|
|
|
|
|
uses
|
2009-03-05 18:57:06 +00:00
|
|
|
|
Forms, Controls, cxControls, uDataTableUtils, uBizContacto,
|
|
|
|
|
|
uDataModuleContactos, uDataModuleBase, uDAInterfaces,
|
2007-06-21 16:02:50 +00:00
|
|
|
|
FactuGES_Intf, uEditorPreviewFacturaCliente, uEditorPreview,
|
|
|
|
|
|
uROTypes, schFacturasClienteClient_Intf;
|
|
|
|
|
|
|
|
|
|
|
|
{ TDAClientDataModule1 }
|
|
|
|
|
|
|
|
|
|
|
|
function TdmFacturasCliente.GetItems: IBizFacturasCliente;
|
|
|
|
|
|
var
|
|
|
|
|
|
dtCabecera: TDACDSDataTable;
|
|
|
|
|
|
dtDetalles: TDACDSDataTable;
|
|
|
|
|
|
ACursor: TCursor;
|
|
|
|
|
|
begin
|
|
|
|
|
|
ACursor := Screen.Cursor;
|
|
|
|
|
|
Screen.Cursor := crHourGlass;
|
|
|
|
|
|
try
|
|
|
|
|
|
dtCabecera := TDACDSDataTable.Create(NIL);
|
|
|
|
|
|
CloneDataTable(tbl_FacturasCliente, dtCabecera);
|
|
|
|
|
|
with dtCabecera do
|
|
|
|
|
|
begin
|
|
|
|
|
|
BusinessRulesID := BIZ_FACTURASCLIENTE;
|
|
|
|
|
|
FieldByName(fld_FacturasClienteDESCUENTO).BusinessRulesID := 'Client.Field.Descuento';
|
|
|
|
|
|
FieldByName(fld_FacturasClienteIVA).BusinessRulesID := 'Client.Field.IVA';
|
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
|
|
dtDetalles := TDACDSDataTable.Create(NIL);
|
|
|
|
|
|
CloneDataTable(tbl_DetallesFacturasCliente, dtDetalles);
|
|
|
|
|
|
with dtDetalles do
|
|
|
|
|
|
begin
|
|
|
|
|
|
BusinessRulesID := BIZ_DETALLESFACTURASCLIENTE;
|
|
|
|
|
|
DetailOptions := DetailOptions - [dtDisableLogOfCascadeDeletes, dtDisableLogOfCascadeUpdates];
|
|
|
|
|
|
|
|
|
|
|
|
FieldByName(fld_DetallesFacturasClienteCANTIDAD).BusinessRulesID := 'Client.Field.Cantidad';
|
|
|
|
|
|
FieldByName(fld_DetallesFacturasClienteIMPORTEUNIDAD).BusinessRulesID := 'Client.Field.ImporteUnidad';
|
|
|
|
|
|
FieldByName(fld_DetallesFacturasClienteTIPO).BusinessRulesID := 'Client.Field.TipoDetalle';
|
|
|
|
|
|
FieldByName(fld_DetallesFacturasClienteVISIBLE).BusinessRulesID := 'Client.Field.Visible';
|
2010-03-14 18:07:47 +00:00
|
|
|
|
FieldByName(fld_DetallesFacturasClienteVALORADO).BusinessRulesID := 'Client.Field.Valorado';
|
2007-06-21 16:02:50 +00:00
|
|
|
|
end;
|
|
|
|
|
|
(dtCabecera as IBizFacturasCliente).Detalles := (dtDetalles as IBizDetallesFacturasCliente);
|
|
|
|
|
|
|
|
|
|
|
|
Result := (dtCabecera as IBizFacturasCliente);
|
|
|
|
|
|
finally
|
|
|
|
|
|
Screen.Cursor := ACursor;
|
|
|
|
|
|
end;
|
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
|
|
procedure TdmFacturasCliente.DAClientDataModuleCreate(Sender: TObject);
|
|
|
|
|
|
begin
|
|
|
|
|
|
RORemoteService.Channel := dmBase.Channel;
|
|
|
|
|
|
RORemoteService.Message := dmBase.Message;
|
|
|
|
|
|
Adapter := dmBase.Adapter;
|
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function TdmFacturasCliente.GetItem: IBizFacturasCliente;
|
|
|
|
|
|
var
|
|
|
|
|
|
dtCabecera: TDACDSDataTable;
|
|
|
|
|
|
dtDetalles: TDACDSDataTable;
|
|
|
|
|
|
ACursor: TCursor;
|
|
|
|
|
|
begin
|
|
|
|
|
|
{ ACursor := Screen.Cursor;
|
|
|
|
|
|
Screen.Cursor := crHourGlass;
|
|
|
|
|
|
try
|
|
|
|
|
|
dtCabecera := TDACDSDataTable.Create(NIL);
|
|
|
|
|
|
CloneDataTable(tbl_AlbaranCliente, dtCabecera);
|
|
|
|
|
|
with dtCabecera do
|
|
|
|
|
|
begin
|
|
|
|
|
|
BusinessRulesID := BIZ_ALBARANCLIENTE;
|
|
|
|
|
|
FieldByName(fld_AlbaranClienteDESCUENTO).BusinessRulesID := 'Client.Field.Descuento';
|
|
|
|
|
|
FieldByName(fld_AlbaranClienteIVA).BusinessRulesID := 'Client.Field.IVA';
|
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
|
|
dtDetalles := TDACDSDataTable.Create(NIL);
|
|
|
|
|
|
CloneDataTable(tbl_DetallesAlbaranCliente, dtDetalles);
|
|
|
|
|
|
with dtDetalles do
|
|
|
|
|
|
begin
|
|
|
|
|
|
BusinessRulesID := BIZ_DETALLESALBARANCLIENTE;
|
|
|
|
|
|
DetailOptions := DetailOptions - [dtDisableLogOfCascadeDeletes, dtDisableLogOfCascadeUpdates];
|
|
|
|
|
|
|
|
|
|
|
|
FieldByName(fld_DetallesAlbaranClienteCANTIDAD).BusinessRulesID := 'Client.Field.Cantidad';
|
|
|
|
|
|
FieldByName(fld_DetallesAlbaranClienteIMPORTEUNIDAD).BusinessRulesID := 'Client.Field.ImporteUnidad';
|
|
|
|
|
|
FieldByName(fld_DetallesAlbaranClienteTIPO).BusinessRulesID := 'Client.Field.TipoDetalle';
|
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
|
|
with (dtAlbaranes as IBizAlbaranesCliente) do
|
|
|
|
|
|
begin
|
|
|
|
|
|
Detalles := (dtDetalles as IBizDetallesAlbaranCliente);
|
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
|
|
Result := (dtAlbaranes as IBizAlbaranesCliente);
|
|
|
|
|
|
finally
|
|
|
|
|
|
Screen.Cursor := ACursor;
|
|
|
|
|
|
end;}
|
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
|
|
function TdmFacturasCliente.GetNextAutoinc: integer;
|
|
|
|
|
|
begin
|
|
|
|
|
|
Result := (RORemoteService as IsrvFacturasCliente).GetNextAutoinc;
|
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
|
|
procedure TdmFacturasCliente.Preview(const Codigo: Integer);
|
|
|
|
|
|
var
|
|
|
|
|
|
AStream: TROBinaryMemoryStream;
|
|
|
|
|
|
AEditorPreviewFacturaCliente : TfEditorPreviewFacturaCliente;
|
|
|
|
|
|
begin
|
|
|
|
|
|
AEditorPreviewFacturaCliente := TfEditorPreviewFacturaCliente.Create(Application);
|
|
|
|
|
|
try
|
|
|
|
|
|
AStream := (RORemoteService as IsrvFacturasCliente).GenerateReport(Codigo, 0);
|
|
|
|
|
|
AEditorPreviewFacturaCliente.Report.PreviewPages.LoadFromStream(AStream);
|
|
|
|
|
|
AEditorPreviewFacturaCliente.Codigo := Codigo;
|
|
|
|
|
|
AEditorPreviewFacturaCliente.ShowModal;
|
|
|
|
|
|
finally
|
|
|
|
|
|
AEditorPreviewFacturaCliente.Release;
|
|
|
|
|
|
AStream.Free;
|
|
|
|
|
|
end;
|
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
|
|
function TdmFacturasCliente.DarNuevaReferencia: String;
|
|
|
|
|
|
begin
|
|
|
|
|
|
Result := (RORemoteService as IsrvFacturasCliente).DarNuevaReferencia;
|
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
|
|
function TdmFacturasCliente.PuedoEliminarFactura(CodigoFactura: Integer): Boolean;
|
|
|
|
|
|
begin
|
|
|
|
|
|
Result := (RORemoteService as IsrvFacturasCliente).PuedoEliminarFactura(CodigoFactura);
|
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
|
|
procedure TdmFacturasCliente.Print(const Codigo: Integer);
|
|
|
|
|
|
var
|
|
|
|
|
|
AStream: TROBinaryMemoryStream;
|
|
|
|
|
|
AEditorPreview : TfEditorPreview;
|
|
|
|
|
|
begin
|
|
|
|
|
|
AEditorPreview := TfEditorPreview.Create(Application);
|
|
|
|
|
|
try
|
|
|
|
|
|
AStream := (RORemoteService as IsrvFacturasCliente).GenerateReport(Codigo, 0);
|
|
|
|
|
|
AEditorPreview.Report.PreviewPages.LoadFromStream(AStream);
|
|
|
|
|
|
AEditorPreview.Print;
|
|
|
|
|
|
finally
|
|
|
|
|
|
AEditorPreview.Release;
|
|
|
|
|
|
AStream.Free;
|
|
|
|
|
|
end;
|
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
|
|
procedure TdmFacturasCliente.Refrescar(lReport: TfrxReport; const Codigo, TamLetra: Integer);
|
|
|
|
|
|
var
|
|
|
|
|
|
AStream: TROBinaryMemoryStream;
|
|
|
|
|
|
begin
|
|
|
|
|
|
AStream := (RORemoteService as IsrvFacturasCliente).GenerateReport(Codigo, TamLetra);
|
|
|
|
|
|
lReport.PreviewPages.LoadFromStream(AStream);
|
|
|
|
|
|
lReport.ShowPreparedReport;
|
|
|
|
|
|
end;
|
|
|
|
|
|
|
2009-03-05 18:57:06 +00:00
|
|
|
|
function TdmFacturasCliente.DarListaAnosFacturas: 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;
|
|
|
|
|
|
|
|
|
|
|
|
procedure TdmFacturasCliente.FiltrarAno(AFacturas: IBizFacturasCliente; AWhereDataTable: String; const Ano: String);
|
|
|
|
|
|
var
|
|
|
|
|
|
FechaIni: String;
|
|
|
|
|
|
FechaFin: String;
|
|
|
|
|
|
|
|
|
|
|
|
begin
|
|
|
|
|
|
AFacturas.DataTable.Where.Clear;
|
|
|
|
|
|
AFacturas.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 AFacturas.DataTable.Where do
|
|
|
|
|
|
begin
|
|
|
|
|
|
if NotEmpty then
|
|
|
|
|
|
AddOperator(opAND);
|
|
|
|
|
|
AddCondition(fld_FacturasClienteFECHAFACTURA, cMajorOrEqual, FechaIni);
|
|
|
|
|
|
AddOperator(opAND);
|
|
|
|
|
|
AddCondition(fld_FacturasClienteFECHAFACTURA, cLessOrEqual, FechaFin);
|
|
|
|
|
|
end;
|
|
|
|
|
|
end;
|
|
|
|
|
|
end;
|
|
|
|
|
|
|
2007-06-21 16:02:50 +00:00
|
|
|
|
initialization
|
|
|
|
|
|
dmFacturasCliente := TdmFacturasCliente.Create(nil);
|
|
|
|
|
|
|
|
|
|
|
|
finalization
|
|
|
|
|
|
FreeAndNil(dmFacturasCliente);
|
|
|
|
|
|
|
|
|
|
|
|
end.
|