256 lines
8.3 KiB
ObjectPascal
256 lines
8.3 KiB
ObjectPascal
|
|
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;
|
|||
|
|
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);
|
|||
|
|
end;
|
|||
|
|
|
|||
|
|
var
|
|||
|
|
dmAlbaranesCliente: TdmAlbaranesCliente;
|
|||
|
|
|
|||
|
|
implementation
|
|||
|
|
|
|||
|
|
{$R *.DFM}
|
|||
|
|
|
|||
|
|
uses
|
|||
|
|
Forms, Controls, uDataTableUtils, uBizContacto, uDataModulePagos,
|
|||
|
|
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;
|
|||
|
|
|
|||
|
|
initialization
|
|||
|
|
dmAlbaranesCliente := TdmAlbaranesCliente.Create(nil);
|
|||
|
|
|
|||
|
|
finalization
|
|||
|
|
FreeAndNil(dmAlbaranesCliente);
|
|||
|
|
|
|||
|
|
end.
|