142 lines
4.4 KiB
ObjectPascal
142 lines
4.4 KiB
ObjectPascal
unit EDI_Sales_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_Sales }
|
|
TEDI_Sales = class(TDARemoteService, IEDI_Sales)
|
|
private
|
|
procedure InsertarLog(OK : Boolean; Error_msg : String = '');
|
|
protected
|
|
{ IEDI_Sales methods }
|
|
function CargarFicheroEDI(const FicheroCAB: String; const FicheroLUG: String; const FicheroART: String; out MsgError: String): Boolean;
|
|
end;
|
|
|
|
implementation
|
|
|
|
{$R *.dfm}
|
|
uses
|
|
{Generated:} VARELA_Invk, uDataModuleServer, uDataModuleEDI_Sales,
|
|
EDI_Log_Impl, JclFileUtils, DateUtils;
|
|
|
|
procedure Create_EDI_Sales(out anInstance : IUnknown);
|
|
begin
|
|
anInstance := TEDI_Sales.Create(nil);
|
|
end;
|
|
|
|
{ EDI_Sales }
|
|
function TEDI_Sales.CargarFicheroEDI(const FicheroCAB: String; const FicheroLUG: String; const FicheroART: 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 + FicheroLUG, AAlmacen + FicheroLUG);
|
|
FileMove(ADirTemp + FicheroART, AAlmacen + FicheroART);
|
|
FileMove(ADirTemp + FicheroART, AAlmacen + 'CONVEN.TXT');
|
|
DeleteDirectory(ADirTemp, False);
|
|
end;
|
|
|
|
begin
|
|
Result := False;
|
|
NumRegNuevos := 0;
|
|
|
|
// Hay que comprobar que existen los ficheros.
|
|
ADirEntrada := PathAddSeparator(dmServer.FDirEntrada);
|
|
|
|
if not FileExists(ADirEntrada + FicheroCAB) or
|
|
not FileExists(ADirEntrada + FicheroLUG) or
|
|
not FileExists(ADirEntrada + FicheroART) then
|
|
begin
|
|
MsgError := 'No hay ficheros de datos';
|
|
InsertarLog(False, MsgError + ' (CargarFicheroEDI1 SLS)');
|
|
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 + FicheroLUG, ADirTemp + FicheroLUG);
|
|
FileMove(ADirEntrada + FicheroART, ADirTemp + FicheroART);
|
|
FileMove(ADirEntrada + FicheroART, ADirTemp + 'CONVEN.TXT');
|
|
except
|
|
on E: Exception do
|
|
begin
|
|
MsgError := E.Message;
|
|
InsertarLog(False, MsgError + ' (CargarFicheroEDI2 SLS)');
|
|
Exit;
|
|
end;
|
|
end;
|
|
|
|
try
|
|
try
|
|
dmEDISales.CargarFicheros (ADirTemp + FicheroCAB, ADirTemp + FicheroLUG, ADirTemp + FicheroART, NumRegNuevos);
|
|
if NumRegNuevos > 0 then
|
|
InsertarLog(True, Format('Se han cargado %d registros de ventas nuevos', [NumRegNuevos]))
|
|
else
|
|
InsertarLog(True, 'El fichero se ha cargado pero no hay registros de ventas nuevos');
|
|
Result := True;
|
|
finally
|
|
GuardarFicheros;
|
|
dmServer.BorrarFicherosDeCargaAntiguos;
|
|
end;
|
|
except
|
|
on E: Exception do
|
|
begin
|
|
MsgError := E.Message;
|
|
InsertarLog(False, MsgError + ' (CargarFicheroEDI3 SLS)');
|
|
end;
|
|
end;
|
|
end;
|
|
end;
|
|
|
|
procedure TEDI_Sales.InsertarLog(OK: Boolean; Error_msg: String);
|
|
var
|
|
LogService : IEDI_Log;
|
|
begin
|
|
LogService := EDI_Log_Impl.TEDI_Log.Create(Self);
|
|
try
|
|
LogService.InsertarLog(Now, 'SLSRPT', OK, Error_msg);
|
|
finally
|
|
LogService := nil;
|
|
end;
|
|
end;
|
|
|
|
initialization
|
|
TROClassFactory.Create('EDI_Sales', Create_EDI_Sales, TEDI_Sales_Invoker);
|
|
|
|
finalization
|
|
|
|
end.
|