Varela_PuntosVenta/Source/Servidor/EDI_Inventary_Impl.pas

139 lines
4.4 KiB
ObjectPascal

unit EDI_Inventary_Impl;
{----------------------------------------------------------------------------}
{ This unit was automatically generated by the RemObjects SDK after reading }
{ the RODL file associated with this project . }
{ }
{ This is where you are supposed to code the implementation of your objects. }
{----------------------------------------------------------------------------}
{$I Remobjects.inc}
interface
uses
{vcl:} Classes, SysUtils,
{RemObjects:} uROXMLIntf, uROClientIntf, uROTypes, uROServer, uROServerIntf, uROSessions,
{Required:} uRORemoteDataModule,
{Ancestor Implementation:} DARemoteService_Impl,
{Used RODLs:} DataAbstract3_Intf,
{Generated:} VARELA_Intf;
type
{ TEDI_Inventary }
TEDI_Inventary = class(TDARemoteService, IEDI_Inventary)
private
procedure InsertarLog(OK : Boolean; Error_msg : String = '');
protected
{ IEDI_Inventary methods }
function CargarFicheroEDI(const FicheroCAB: String; const FicheroLIN: String; const FicheroCANT: String; out MsgError: String): Boolean;
end;
implementation
{$R *.dfm}
uses
{Generated:} VARELA_Invk, uDataModuleServer,
JclFileUtils, DateUtils, EDI_Log_Impl, uDataModuleEDI_Inventary;
procedure Create_EDI_Inventary(out anInstance : IUnknown);
begin
anInstance := TEDI_Inventary.Create(nil);
end;
{ EDI_Inventary }
function TEDI_Inventary.CargarFicheroEDI(const FicheroCAB: String; const FicheroLIN: String; const FicheroCANT: String; out MsgError: String): Boolean;
var
ADirEntrada : String;
ADirTemp : String;
NumRegNuevos : Integer;
procedure GuardarFicheros;
var
AAlmacen : String;
ADate : String;
begin
DateTimeToString(ADate, 'yyyymmddhhnn', Now);
AAlmacen := PathAddSeparator(dmServer.FDirAlmacen);
AAlmacen := PathAddSeparator(AAlmacen + ADate);
if not DirectoryExists(AAlmacen) then
ForceDirectories(AAlmacen);
FileMove(ADirTemp + FicheroCAB, AAlmacen + FicheroCAB);
FileMove(ADirTemp + FicheroLIN, AAlmacen + FicheroLIN);
FileMove(ADirTemp + FicheroCANT, AAlmacen + FicheroCANT);
DeleteDirectory(ADirTemp, False);
end;
begin
Result := False;
// Hay que comprobar que existen los ficheros.
ADirEntrada := PathAddSeparator(dmServer.FDirEntrada);
if not FileExists(ADirEntrada + FicheroCAB) or
not FileExists(ADirEntrada + FicheroLIN) or
not FileExists(ADirEntrada + FicheroCANT) then
begin
MsgError := 'No hay ficheros de datos';
InsertarLog(False, MsgError + ' (CargarFicheroEDI1 INV)');
end
else begin
// Muevo los ficheros de carga a un directorio temporal
ADirTemp := PathAddSeparator(ADirEntrada + GetTempDirectory(ADirEntrada));
try
if not DirectoryExists(ADirTemp) then
ForceDirectories(ADirTemp);
FileMove(ADirEntrada + FicheroCAB, ADirTemp + FicheroCAB);
FileMove(ADirEntrada + FicheroLIN, ADirTemp + FicheroLIN);
FileMove(ADirEntrada + FicheroCANT, ADirTemp + FicheroCANT);
except
on E: Exception do
begin
MsgError := E.Message;
InsertarLog(False, MsgError + ' (CargarFicheroEDI2 INV)');
Exit;
end;
end;
try
try
dmEDIInventary.CargarFicheros (ADirTemp + FicheroCAB, ADirTemp + FicheroLIN, ADirTemp + FicheroCANT, NumRegNuevos);
if NumRegNuevos > 0 then
InsertarLog(True, Format('Se han cargado %d registros de inventario nuevos', [NumRegNuevos]))
else
InsertarLog(True, 'El fichero se ha cargado pero no hay registros de inventario nuevos');
Result := True;
finally
GuardarFicheros;
dmServer.BorrarFicherosDeCargaAntiguos;
end;
except
on E: Exception do
begin
MsgError := E.Message;
InsertarLog(False, MsgError + ' (CargarFicheroEDI3 INV)');
end;
end;
end;
end;
procedure TEDI_Inventary.InsertarLog(OK: Boolean; Error_msg: String);
var
LogService : IEDI_Log;
begin
LogService := EDI_Log_Impl.TEDI_Log.Create(Self);
try
LogService.InsertarLog(Now, 'INVRPT', OK, Error_msg);
finally
LogService := nil;
end;
end;
initialization
TROClassFactory.Create('EDI_Inventary', Create_EDI_Inventary, TEDI_Inventary_Invoker);
finalization
end.