2007-06-21 16:02:50 +00:00
|
|
|
|
unit uDataModuleAlbaranesCliente;
|
|
|
|
|
|
|
|
|
|
|
|
interface
|
|
|
|
|
|
|
|
|
|
|
|
uses {vcl:} SysUtils, Classes, DB, DBClient,
|
|
|
|
|
|
{RemObjects:} uDAClientDataModule, uDADataTable, uDABINAdapter,
|
|
|
|
|
|
uROServiceComponent, uRORemoteService, uROClient, uROBinMessage,
|
|
|
|
|
|
uROWinInetHttpChannel, uDAScriptingProvider, uDACDSDataTable,
|
|
|
|
|
|
uDADesigntimeCall, uBizAlbaranesCliente, FactuGES_Intf;
|
|
|
|
|
|
|
|
|
|
|
|
type
|
|
|
|
|
|
TdmAlbaranesCliente = class(TDAClientDataModule)
|
|
|
|
|
|
RORemoteService: TRORemoteService;
|
|
|
|
|
|
tbl_AlbaranCliente: TDACDSDataTable;
|
|
|
|
|
|
ds_AlbaranCliente: TDADataSource;
|
|
|
|
|
|
tbl_DetallesAlbaranCliente: TDACDSDataTable;
|
|
|
|
|
|
ds_DetallesAlbaranCliente: TDADataSource;
|
|
|
|
|
|
DADesigntimeCall1: TDADesigntimeCall;
|
|
|
|
|
|
RORemoteService2: TRORemoteService;
|
2009-03-05 18:34:34 +00:00
|
|
|
|
tbl_ListaAnosAlbaranes: TDACDSDataTable;
|
|
|
|
|
|
ds_ListaAnosAlbaranes: TDADataSource;
|
2007-06-21 16:02:50 +00:00
|
|
|
|
procedure DAClientDataModuleCreate(Sender: TObject);
|
|
|
|
|
|
private
|
|
|
|
|
|
{ Private declarations }
|
|
|
|
|
|
public
|
|
|
|
|
|
function GetNextAutoinc : integer;
|
|
|
|
|
|
function GetItem: IBizAlbaranesCliente; overload;
|
|
|
|
|
|
function GetItem(Codigo: Integer): IBizAlbaranesCliente; overload;
|
|
|
|
|
|
function GetItems: IBizAlbaranesCliente;
|
|
|
|
|
|
procedure Print(Const Codigo: Integer);
|
|
|
|
|
|
procedure Preview(Const Codigo: Integer);
|
|
|
|
|
|
function DarNuevaReferencia : String;
|
|
|
|
|
|
function PuedoEliminarAlbaran (CodigoAlbaran : Integer) : Boolean;
|
|
|
|
|
|
function GetItemsSeleccionados(ASource : IBizAlbaranesCliente): IBizAlbaranesCliente;
|
|
|
|
|
|
procedure CambiarSituacion(AAlbaran: IBizAlbaranesCliente);
|
2009-03-05 18:34:34 +00:00
|
|
|
|
|
|
|
|
|
|
function DarListaAnosAlbaranes: TStringList;
|
|
|
|
|
|
procedure FiltrarAno(AAlbaranes: IBizAlbaranesCliente; AWhereDataTable: String; const Ano: String);
|
2007-06-21 16:02:50 +00:00
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
|
|
var
|
|
|
|
|
|
dmAlbaranesCliente: TdmAlbaranesCliente;
|
|
|
|
|
|
|
|
|
|
|
|
implementation
|
|
|
|
|
|
|
|
|
|
|
|
{$R *.DFM}
|
|
|
|
|
|
|
|
|
|
|
|
uses
|
2009-03-05 18:34:34 +00:00
|
|
|
|
Forms, Controls, cxControls, uDataTableUtils, uBizContacto, uDataModulePagos,
|
2007-06-21 16:02:50 +00:00
|
|
|
|
uDataModuleContactos, uDataModuleBase, schAlbaranesClienteClient_Intf,
|
|
|
|
|
|
uEditorPreview, uROTypes, uDBSelectionList, uDAInterfaces;
|
|
|
|
|
|
|
|
|
|
|
|
{ TDAClientDataModule1 }
|
|
|
|
|
|
|
|
|
|
|
|
function TdmAlbaranesCliente.GetItems: IBizAlbaranesCliente;
|
|
|
|
|
|
var
|
|
|
|
|
|
dtAlbaranes: TDACDSDataTable;
|
|
|
|
|
|
dtDetalles: TDACDSDataTable;
|
|
|
|
|
|
ACursor: TCursor;
|
|
|
|
|
|
begin
|
|
|
|
|
|
ACursor := Screen.Cursor;
|
|
|
|
|
|
Screen.Cursor := crHourGlass;
|
|
|
|
|
|
try
|
|
|
|
|
|
dtAlbaranes := TDACDSDataTable.Create(NIL);
|
|
|
|
|
|
CloneDataTable(tbl_AlbaranCliente, dtAlbaranes);
|
|
|
|
|
|
with dtAlbaranes 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';
|
|
|
|
|
|
|
|
|
|
|
|
FieldByName(fld_DetallesAlbaranClientePUNTOS).BusinessRulesID := 'Client.Field.Puntos';
|
|
|
|
|
|
FieldByName(fld_DetallesAlbaranClienteIMPORTEPUNTOS).BusinessRulesID := 'Client.Field.ImportePuntos';
|
|
|
|
|
|
|
|
|
|
|
|
FieldByName(fld_DetallesAlbaranClienteVISIBLE).BusinessRulesID := 'Client.Field.Visible';
|
|
|
|
|
|
end;
|
|
|
|
|
|
(dtAlbaranes as IBizAlbaranesCliente).Detalles := (dtDetalles as IBizDetallesAlbaranCliente);
|
|
|
|
|
|
|
|
|
|
|
|
Result := (dtAlbaranes as IBizAlbaranesCliente);
|
|
|
|
|
|
finally
|
|
|
|
|
|
Screen.Cursor := ACursor;
|
|
|
|
|
|
end;
|
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
|
|
procedure TdmAlbaranesCliente.DAClientDataModuleCreate(Sender: TObject);
|
|
|
|
|
|
begin
|
|
|
|
|
|
RORemoteService.Channel := dmBase.Channel;
|
|
|
|
|
|
RORemoteService.Message := dmBase.Message;
|
|
|
|
|
|
Adapter := dmBase.Adapter;
|
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function TdmAlbaranesCliente.GetItem: IBizAlbaranesCliente;
|
|
|
|
|
|
var
|
|
|
|
|
|
dtAlbaranes: TDACDSDataTable;
|
|
|
|
|
|
dtDetalles: TDACDSDataTable;
|
|
|
|
|
|
ACursor: TCursor;
|
|
|
|
|
|
begin
|
|
|
|
|
|
ACursor := Screen.Cursor;
|
|
|
|
|
|
Screen.Cursor := crHourGlass;
|
|
|
|
|
|
try
|
|
|
|
|
|
dtAlbaranes := TDACDSDataTable.Create(NIL);
|
|
|
|
|
|
CloneDataTable(tbl_AlbaranCliente, dtAlbaranes);
|
|
|
|
|
|
with dtAlbaranes 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;
|
|
|
|
|
|
|
|
|
|
|
|
(dtAlbaranes as IBizAlbaranesCliente).Detalles := (dtDetalles as IBizDetallesAlbaranCliente);
|
|
|
|
|
|
|
|
|
|
|
|
Result := (dtAlbaranes as IBizAlbaranesCliente);
|
|
|
|
|
|
finally
|
|
|
|
|
|
Screen.Cursor := ACursor;
|
|
|
|
|
|
end;
|
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
|
|
function TdmAlbaranesCliente.GetNextAutoinc: integer;
|
|
|
|
|
|
begin
|
|
|
|
|
|
Result := (RORemoteService as IsrvAlbaranesCliente).GetNextAutoinc;
|
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
|
|
procedure TdmAlbaranesCliente.Preview(const Codigo: Integer);
|
|
|
|
|
|
var
|
|
|
|
|
|
AStream: TROBinaryMemoryStream;
|
|
|
|
|
|
AEditorPreview : TfEditorPreview;
|
|
|
|
|
|
begin
|
|
|
|
|
|
AEditorPreview := TfEditorPreview.Create(Application);
|
|
|
|
|
|
try
|
|
|
|
|
|
AStream := (RORemoteService as IsrvAlbaranesCliente).GenerateReport(Codigo);
|
|
|
|
|
|
AEditorPreview.Report.PreviewPages.LoadFromStream(AStream);
|
|
|
|
|
|
AEditorPreview.ShowModal;
|
|
|
|
|
|
finally
|
|
|
|
|
|
AEditorPreview.Release;
|
|
|
|
|
|
AStream.Free;
|
|
|
|
|
|
end;
|
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
|
|
function TdmAlbaranesCliente.DarNuevaReferencia: String;
|
|
|
|
|
|
begin
|
|
|
|
|
|
Result := (RORemoteService as IsrvAlbaranesCliente).DarNuevaReferencia;
|
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
|
|
function TdmAlbaranesCliente.PuedoEliminarAlbaran(
|
|
|
|
|
|
CodigoAlbaran: Integer): Boolean;
|
|
|
|
|
|
begin
|
|
|
|
|
|
Result := (RORemoteService as IsrvAlbaranesCliente).PuedoEliminarAlbaran(CodigoAlbaran);
|
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
|
|
procedure TdmAlbaranesCliente.Print(const Codigo: Integer);
|
|
|
|
|
|
var
|
|
|
|
|
|
AStream: TROBinaryMemoryStream;
|
|
|
|
|
|
AEditorPreview : TfEditorPreview;
|
|
|
|
|
|
begin
|
|
|
|
|
|
AEditorPreview := TfEditorPreview.Create(Application);
|
|
|
|
|
|
try
|
|
|
|
|
|
AStream := (RORemoteService as IsrvAlbaranesCliente).GenerateReport(Codigo);
|
|
|
|
|
|
AEditorPreview.Report.PreviewPages.LoadFromStream(AStream);
|
|
|
|
|
|
AEditorPreview.Print;
|
|
|
|
|
|
finally
|
|
|
|
|
|
AEditorPreview.Release;
|
|
|
|
|
|
AStream.Free;
|
|
|
|
|
|
end;
|
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
|
|
function TdmAlbaranesCliente.GetItemsSeleccionados(ASource: IBizAlbaranesCliente): IBizAlbaranesCliente;
|
|
|
|
|
|
var
|
|
|
|
|
|
aObj : ISelectedRowList;
|
|
|
|
|
|
dtAlbaran : IBizAlbaranesCliente;
|
|
|
|
|
|
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
|
|
|
|
|
|
dtAlbaran := GetItems;
|
|
|
|
|
|
end
|
|
|
|
|
|
else
|
|
|
|
|
|
raise Exception.Create('Interface no soportada (GetItemsSeleccionados)');
|
|
|
|
|
|
|
|
|
|
|
|
if dtAlbaran.DataTable.Active then
|
|
|
|
|
|
dtAlbaran.DataTable.Active := False;
|
|
|
|
|
|
with dtAlbaran.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('ALBARANPAGO.' + fld_AlbaranClienteCODIGO + ' = ' + IntToStr(ASource.CODIGO));
|
|
|
|
|
|
end;
|
|
|
|
|
|
end;
|
|
|
|
|
|
Result := dtAlbaran;
|
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
|
|
function TdmAlbaranesCliente.GetItem(Codigo: Integer): IBizAlbaranesCliente;
|
|
|
|
|
|
var
|
|
|
|
|
|
AAlbaran : IBizAlbaranesCliente;
|
|
|
|
|
|
begin
|
|
|
|
|
|
AAlbaran:= GetItems;
|
|
|
|
|
|
with AAlbaran.DataTable.Where do
|
|
|
|
|
|
AddText('ALBARANPAGO.' + fld_AlbaranClienteCODIGO + ' = ' + IntToStr(Codigo));
|
|
|
|
|
|
Result := AAlbaran;
|
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
|
|
procedure TdmAlbaranesCliente.CambiarSituacion(AAlbaran: IBizAlbaranesCliente);
|
|
|
|
|
|
var
|
|
|
|
|
|
FechaPago: TDateTime;
|
|
|
|
|
|
begin
|
|
|
|
|
|
if Assigned(AAlbaran) then
|
|
|
|
|
|
begin
|
|
|
|
|
|
//El c<>digo presupuesto no ayudar<61> a identificar el montaje relacionado
|
|
|
|
|
|
if dmPagos.AnadirPagoCliente(AAlbaran.Cliente, AAlbaran.CODIGOPRESUPUESTO, AAlbaran.REFERENCIA, AAlbaran.IMPORTETOTAL, FechaPago) then
|
|
|
|
|
|
begin
|
|
|
|
|
|
AAlbaran.Edit;
|
|
|
|
|
|
AAlbaran.FECHAPAGO := FechaPago;
|
|
|
|
|
|
AAlbaran.Post;
|
|
|
|
|
|
AAlbaran.DataTable.ApplyUpdates;
|
|
|
|
|
|
end;
|
|
|
|
|
|
end;
|
|
|
|
|
|
end;
|
|
|
|
|
|
|
2009-03-05 18:34:34 +00:00
|
|
|
|
function TdmAlbaranesCliente.DarListaAnosAlbaranes: TStringList;
|
|
|
|
|
|
var
|
|
|
|
|
|
AListaAnos: TStringList;
|
|
|
|
|
|
begin
|
|
|
|
|
|
AListaAnos := TStringList.Create;
|
|
|
|
|
|
ShowHourglassCursor;
|
|
|
|
|
|
try
|
|
|
|
|
|
with tbl_ListaAnosAlbaranes 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 TdmAlbaranesCliente.FiltrarAno(AAlbaranes: IBizAlbaranesCliente; AWhereDataTable: String; const Ano: String);
|
|
|
|
|
|
var
|
|
|
|
|
|
FechaIni: String;
|
|
|
|
|
|
FechaFin: String;
|
|
|
|
|
|
|
|
|
|
|
|
begin
|
|
|
|
|
|
AAlbaranes.DataTable.Where.Clear;
|
|
|
|
|
|
AAlbaranes.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 AAlbaranes.DataTable.Where do
|
|
|
|
|
|
begin
|
|
|
|
|
|
if NotEmpty then
|
|
|
|
|
|
AddOperator(opAND);
|
|
|
|
|
|
AddCondition(fld_AlbaranClienteFECHAALBARAN, cMajorOrEqual, FechaIni);
|
|
|
|
|
|
AddOperator(opAND);
|
|
|
|
|
|
AddCondition(fld_AlbaranClienteFECHAALBARAN, cLessOrEqual, FechaFin);
|
|
|
|
|
|
end;
|
|
|
|
|
|
end;
|
|
|
|
|
|
end;
|
|
|
|
|
|
|
2007-06-21 16:02:50 +00:00
|
|
|
|
initialization
|
|
|
|
|
|
dmAlbaranesCliente := TdmAlbaranesCliente.Create(nil);
|
|
|
|
|
|
|
|
|
|
|
|
finalization
|
|
|
|
|
|
FreeAndNil(dmAlbaranesCliente);
|
|
|
|
|
|
|
|
|
|
|
|
end.
|