Batch job: Finding the file from shared drive based on date
public class AWEPaymentTrackerReadFilesFromDirectory extends RunBaseBatch
{
FilePath filePath, filePathOutbound;
Filename filename;
CommaTextIo fileIO;
Set fileSet;
CommaIo commaIo;
str currentFile;
container lineCon;
RecId recIdSAP, recIdOrlando, recIdNashville, recIdEdison;
date systemDate;
AweHOSPaymentTrackerParameter filePathparameter;
#File
#AviFiles
}
private void getCSVFiles()
{
System.String[] files;
System.Collections.IEnumerator enumerator;
str file;
fileSet = new Set(Types::Container);
files = System.IO.Directory::GetFiles(filePath, '*.csv');
enumerator = files.GetEnumerator();
while (enumerator.MoveNext())
{
file = enumerator.get_Current();
fileSet.add([file]);
}
}
private void GetTxtFiles()
{
System.String[] files;
System.Collections.IEnumerator enumerator;
str file;
fileSet = new Set(Types::Container);
files = System.IO.Directory::GetFiles(filePath, '*.txt');
enumerator = files.GetEnumerator();
while (enumerator.MoveNext())
{
file = enumerator.get_Current();
fileSet.add([file]);
}
}
private void GetXmlFiles()
{
System.String[] files;
System.Collections.IEnumerator enumerator;
str file;
fileSet = new Set(Types::Container);
files = System.IO.Directory::GetFiles(filePathOutbound, '*.xml');
enumerator = files.GetEnumerator();
while (enumerator.MoveNext())
{
file = enumerator.get_Current();
fileSet.add([file]);
}
}
private void readFilesFromDirtecoryACH()
{
SetEnumerator sE;
str filenameLoc, filedate;
date fileDateLoc;
AweHOSPaymentTracker paymentTracker, paymentTrackerLoc;
//filePath = @"\\ame001.americanwaterservices.com\CIFS\Shared\PNC Lockbox\AWRL Lockbox\CC ACH\SK-Completed";
select *from filePathparameter where filePathparameter.FilePathType == FilePathType::Processed && filePathparameter.MethodOfPayment == MethodOfPayment::ACH_CC;
filePath = filePathparameter.FilePath;
systemDate = systemDateGet(); //17\09\2021;
this.getCSVFiles();
sE = fileSet.getEnumerator();
while (sE.moveNext()) // loop through all files
{
filename = sE.current();
filenameLoc = subStr(filename, 95,5);
if (filenameLoc == "ACH_2")
{
filedate = subStr(filename, 99,8);
fileDateLoc = str2Date(filedate, 321);
if (fileDateLoc == systemDate)
{
paymentTracker.TransDate = fileDateLoc;
paymentTracker.PaymMode = 'ACH';
//paymentTracker.Inbound = Inbound::None;
paymentTracker.InboundProcessed = Processed::None;
//paymentTracker.Outbound = Outbound::None;
paymentTracker.OutboundProcessed = Processed::None;
paymentTracker.Processed = Processed::Yes;
paymentTracker.CompanyId = paymentTracker.dataAreaId;
paymentTracker.Remarks = '';
select *from paymentTrackerLoc where paymentTrackerLoc.TransDate == paymentTracker.TransDate && paymentTrackerLoc.PaymMode == paymentTracker.PaymMode;
if (paymentTrackerLoc.TransDate != paymentTracker.TransDate && paymentTrackerLoc.PaymMode != paymentTracker.PaymMode)
{
paymentTracker.insert();
}
}
}
else if (filenameLoc == "CC_20")
{
filedate = subStr(filename, 98,8);
fileDateLoc = str2Date(filedate, 321);
if (fileDateLoc == systemDate)
{
paymentTracker.TransDate = fileDateLoc;
paymentTracker.PaymMode = 'CreditCard';
//paymentTracker.Inbound = Inbound::None;
paymentTracker.InboundProcessed = Processed::None;
//paymentTracker.Outbound = Outbound::None;
paymentTracker.OutboundProcessed = Processed::None;
paymentTracker.Processed = Processed::Yes;
paymentTracker.CompanyId = paymentTracker.dataAreaId;
paymentTracker.Remarks = '';
select *from paymentTrackerLoc where paymentTrackerLoc.TransDate == paymentTracker.TransDate && paymentTrackerLoc.PaymMode == paymentTracker.PaymMode;
if (paymentTrackerLoc.TransDate != paymentTracker.TransDate && paymentTrackerLoc.PaymMode != paymentTracker.PaymMode)
{
paymentTracker.insert();
}
}
}
else if (filenameloc == "CC_XX" || filenameloc == "CC_ZZ")
{
filedate = substr(filename, 101,8);
filedateloc = str2date(filedate, 321);
if (filedateloc == systemdate)
{
paymentTracker.TransDate = fileDateLoc;
if (filenameloc == "CC_XX")
{
paymentTracker.PaymMode = 'CC_XX';
}
else
{
paymentTracker.PaymMode = 'CC_ZZ';
}
paymentTracker.Inbound = Inbound::None;
paymentTracker.InboundProcessed = Processed::None;
paymentTracker.Outbound = Outbound::None;
paymentTracker.OutboundProcessed = Processed::None;
paymentTracker.Processed = Processed::Yes;
paymentTracker.CompanyId = paymentTracker.dataAreaId;
paymentTracker.Remarks = '';
select *from paymentTrackerLoc where paymentTrackerLoc.TransDate == paymentTracker.TransDate && paymentTrackerLoc.PaymMode == paymentTracker.PaymMode;
if (paymentTrackerLoc.TransDate != paymentTracker.TransDate && paymentTrackerLoc.PaymMode != paymentTracker.PaymMode)
{
paymentTracker.insert();
}
}
}
}
info('ACH Done');
}
private void readFilesFromEdisonLibertyInbound()
{
SetEnumerator sE;
str filedate;
date fileDateLoc;
System.DateTime systemDateTime;
//date systemDate;
utcDateTime utcNow;
AweHOSPaymentTracker paymentTracker, paymentTrackerLoc;
boolean RecInster;
//filePath = @"\\Train-ax01\ax\AIF\I082\Inbound\Archive";
select *from filePathparameter where filePathparameter.FilePathType == FilePathType::Inbound && filePathparameter.MethodOfPayment == MethodOfPayment::Edison;
filePath = filePathparameter.FilePath;
this.GetTxtFiles();
sE = fileSet.getEnumerator();
while (sE.moveNext()) // loop through all files
{
filename = sE.current();
filedate = subStr(filename, 60,8);
fileDateLoc = str2Date(filedate, 321);
if (fileDateLoc != systemDate)
{
if (RecInster == false)
{
paymentTracker.TransDate = systemDate;
paymentTracker.PaymMode = 'Edison';
//paymentTracker.Inbound = Inbound::No;
paymentTracker.InboundProcessed = Processed::No;
//paymentTracker.Outbound = Outbound::None;
paymentTracker.OutboundProcessed = Processed::None;
paymentTracker.Processed = Processed::None;
paymentTracker.CompanyId = paymentTracker.dataAreaId;
paymentTracker.Remarks = '';
RecInster = true;
}
}
else if (fileDateLoc == systemDate)
{
paymentTracker.TransDate = systemDate;
paymentTracker.PaymMode = 'Edison';
//paymentTracker.Inbound = Inbound::Yes;
paymentTracker.InboundProcessed = Processed::Yes;
//paymentTracker.Outbound = Outbound::None;
paymentTracker.OutboundProcessed = Processed::None;
paymentTracker.Processed = Processed::None;
paymentTracker.CompanyId = paymentTracker.dataAreaId;
paymentTracker.Remarks = '';
}
}
select *from paymentTrackerLoc where paymentTrackerLoc.TransDate == paymentTracker.TransDate && paymentTrackerLoc.PaymMode == paymenttracker.PaymMode;
if (paymentTrackerLoc.TransDate != paymentTracker.TransDate && paymentTrackerLoc.PaymMode != paymentTracker.PaymMode)
{
paymentTracker.insert();
recIdEdison = paymentTracker.recid;
}
}
private void readFilesFromEdisonLibertyOutbound()
{
SetEnumerator sE, sEOutbound;
str filedate;
date fileDateLoc;
System.DateTime systemDateTime;
//date systemDate;
utcDateTime utcNow;
boolean recInsert;
AweHOSPaymentTracker paymentTrackerLoc;
//filePathOutbound = @"\\ame001.americanwaterservices.com\CIFS\shared\dynamics\Training\ax\SKS\PNC Lockbox\AWRL Lockbox\EdisonLiberty\SK-Completed";
select *from filePathparameter where filePathparameter.FilePathType == FilePathType::Outbound && filePathparameter.MethodOfPayment == MethodOfPayment::Edison;
filePathOutbound = filePathparameter.FilePath;
this.GetXmlFiles();
sEOutbound = fileSet.getEnumerator();
while (sEOutbound.moveNext()) // loop through all files
{
filename = sEOutbound.current();
filedate = subStr(filename, 125,8);
fileDateLoc = str2Date(filedate, 321);
ttsBegin;
if (fileDateLoc != systemDate)
{
if (recInsert == false)
{
select forUpdate paymentTrackerLoc where paymentTrackerLoc.RecId == recIdEdison;
if (paymentTrackerLoc)
{
//paymentTrackerLoc.Outbound = Outbound::No;
paymentTrackerLoc.OutboundProcessed = Processed::No;
paymentTrackerLoc.update();
}
recInsert = true;
}
}
else if (fileDateLoc == systemDate)
{
select forUpdate paymentTrackerLoc where paymentTrackerLoc.RecId == recIdEdison;
if (paymentTrackerLoc)
{
//paymentTrackerLoc.Outbound = Outbound::Yes;
paymentTrackerLoc.OutboundProcessed = Processed::Yes;
paymentTrackerLoc.doUpdate();
}
}
ttsCommit;
}
info('Edison Liberty Done');
}
private void readFilesFromNashvilleInbound()
{
SetEnumerator sE;
str filedate;
date fileDateLoc;
System.DateTime systemDateTime;
//date systemDate;
utcDateTime utcNow;
AweHOSPaymentTracker paymentTracker, paymentTrackerLoc;
boolean RecInster;
//filePath = @"\\Train-ax01\ax\AIF\I099\Inbound\Archive";
select *from filePathparameter where filePathparameter.FilePathType == FilePathType::Inbound && filePathparameter.MethodOfPayment == MethodOfPayment::Nashville;
filePath = filePathparameter.FilePath;
this.GetTxtFiles();
sE = fileSet.getEnumerator();
while (sE.moveNext()) // loop through all files
{
filename = sE.current();
filedate = subStr(filename, 48,8);
fileDateLoc = str2Date(filedate, 123);
if (fileDateLoc != systemDate)
{
if (RecInster == false)
{
paymentTracker.TransDate = systemDate;
paymentTracker.PaymMode = 'Nashville';
//paymentTracker.Inbound = Inbound::No;
paymentTracker.InboundProcessed = Processed::No;
//paymentTracker.Outbound = Outbound::None;
paymentTracker.OutboundProcessed = Processed::None;
paymentTracker.Processed = Processed::None;
paymentTracker.CompanyId = paymentTracker.dataAreaId;
paymentTracker.Remarks = '';
RecInster = true;
}
}
else if (fileDateLoc == systemDate)
{
paymentTracker.TransDate = systemDate;
paymentTracker.PaymMode = 'Nashville';
//paymentTracker.Inbound = Inbound::Yes;
paymentTracker.InboundProcessed = Processed::Yes;
//paymentTracker.Outbound = Outbound::None;
paymentTracker.OutboundProcessed = Processed::None;
paymentTracker.Processed = Processed::None;
paymentTracker.CompanyId = paymentTracker.dataAreaId;
paymentTracker.Remarks = '';
}
}
select *from paymentTrackerLoc where paymentTrackerLoc.TransDate == paymentTracker.TransDate && paymentTrackerLoc.PaymMode == paymenttracker.PaymMode;
if (paymentTrackerLoc.TransDate != paymentTracker.TransDate && paymentTrackerLoc.PaymMode != paymentTracker.PaymMode)
{
paymentTracker.insert();
recIdNashville = paymentTracker.recid;
}
}
private void readFilesFromNashvilleOutbound()
{
SetEnumerator sE, sEOutbound;
str filedate;
date fileDateLoc;
System.DateTime systemDateTime;
//date systemDate;
utcDateTime utcNow;
boolean recInsert;
AweHOSPaymentTracker paymentTrackerLoc;
//filePathOutbound = @"\\ame001.americanwaterservices.com\CIFS\shared\dynamics\Training\ax\SKS\PNC Lockbox\AWRL Lockbox\Nashville\SK-Completed";
select *from filePathparameter where filePathparameter.FilePathType == FilePathType::Outbound && filePathparameter.MethodOfPayment == MethodOfPayment::Nashville;
filePathOutbound = filePathparameter.FilePath;
this.GetXmlFiles();
sEOutbound = fileSet.getEnumerator();
while (sEOutbound.moveNext()) // loop through all files
{
filename = sEOutbound.current();
filedate = subStr(filename, 121,8);
fileDateLoc = str2Date(filedate, 321);
ttsBegin;
if (fileDateLoc != systemDate)
{
if (recInsert == false)
{
select forUpdate paymentTrackerLoc where paymentTrackerLoc.RecId == recIdNashville;
if (paymentTrackerLoc)
{
//paymentTrackerLoc.Outbound = Outbound::No;
paymentTrackerLoc.OutboundProcessed = Processed::No;
paymentTrackerLoc.update();
}
recInsert = true;
}
}
else if (fileDateLoc == systemDate)
{
select forUpdate paymentTrackerLoc where paymentTrackerLoc.RecId == recIdNashville;
if (paymentTrackerLoc)
{
//paymentTrackerLoc.Outbound = Outbound::Yes;
paymentTrackerLoc.OutboundProcessed = Processed::Yes;
paymentTrackerLoc.doUpdate();
}
}
ttsCommit;
}
info('Nashville done');
}
private void readFilesFromOrlandoInbound()
{
SetEnumerator sE;
str filedate;
date fileDateLoc;
System.DateTime systemDateTime;
//date systemDate;
utcDateTime utcNow;
AweHOSPaymentTracker paymentTracker, paymentTrackerLoc;
boolean RecInster;
//filePath = @"\\Train-ax01\ax\AIF\CR12414Payment\Inbound\Archive";
select *from filePathparameter where filePathparameter.FilePathType == FilePathType::Inbound &&
filePathparameter.MethodOfPayment == MethodOfPayment::Orlando;
filePath = filePathparameter.FilePath;
this.GetTxtFiles();
sE = fileSet.getEnumerator();
while (sE.moveNext()) // loop through all files
{
filename = sE.current();
filedate = subStr(filename, 60,8);
fileDateLoc = str2Date(filedate, 321);
if (fileDateLoc != systemDate)
{
if (RecInster == false)
{
paymentTracker.TransDate = systemDate;
paymentTracker.PaymMode = 'Orlando';
//paymentTracker.Inbound = Inbound::No;
paymentTracker.InboundProcessed = Processed::No;
//paymentTracker.Outbound = Outbound::None;
paymentTracker.OutboundProcessed = Processed::None;
paymentTracker.Processed = Processed::None;
paymentTracker.CompanyId = paymentTracker.dataAreaId;
paymentTracker.Remarks = '';
RecInster = true;
}
}
else if (fileDateLoc == systemDate)
{
paymentTracker.TransDate = systemDate;
paymentTracker.PaymMode = 'Orlando';
//paymentTracker.Inbound = Inbound::Yes;
paymentTracker.InboundProcessed = Processed::Yes;
//paymentTracker.Outbound = Outbound::None;
paymentTracker.OutboundProcessed = Processed::None;
paymentTracker.Processed = Processed::None;
paymentTracker.CompanyId = paymentTracker.dataAreaId;
paymentTracker.Remarks = '';
}
}
select *from paymentTrackerLoc where paymentTrackerLoc.TransDate == paymentTracker.TransDate && paymentTrackerLoc.PaymMode == paymenttracker.PaymMode;
if (paymentTrackerLoc.TransDate != paymentTracker.TransDate && paymentTrackerLoc.PaymMode != paymentTracker.PaymMode)
{
paymentTracker.insert();
recIdOrlando = paymentTracker.recid;
}
}
private void readFilesFromOrlandoOutbound()
{
SetEnumerator sE, sEOutbound;
str filedate;
date fileDateLoc;
System.DateTime systemDateTime;
//date systemDate;
utcDateTime utcNow;
boolean recInsert;
AweHOSPaymentTracker paymentTrackerLoc;
//filePathOutbound = @"\\ame001.americanwaterservices.com\CIFS\Shared\Dynamics\Training\AX\SKS\PNC Lockbox\AWRL Lockbox\Orlando\SK-Completed";
select *from filePathparameter where filePathparameter.FilePathType == FilePathType::Outbound && filePathparameter.MethodOfPayment == MethodOfPayment::Orlando;
filePathOutbound = filePathparameter.FilePath;
this.GetXmlFiles();
sEOutbound = fileSet.getEnumerator();
while (sEOutbound.moveNext()) // loop through all files
{
filename = sEOutbound.current();
filedate = subStr(filename, 119,8);
fileDateLoc = str2Date(filedate, 321);
ttsBegin;
if (fileDateLoc != systemDate)
{
if (recInsert == false)
{
select forUpdate paymentTrackerLoc where paymentTrackerLoc.RecId == recIdOrlando;
if (paymentTrackerLoc)
{
//paymentTrackerLoc.Outbound = Outbound::No;
paymentTrackerLoc.OutboundProcessed = Processed::No;
paymentTrackerLoc.update();
}
recInsert = true;
}
}
else if (fileDateLoc == systemDate)
{
select forUpdate paymentTrackerLoc where paymentTrackerLoc.RecId == recIdOrlando;
if (paymentTrackerLoc)
{
//paymentTrackerLoc.Outbound = Outbound::Yes;
paymentTrackerLoc.OutboundProcessed = Processed::Yes;
paymentTrackerLoc.doUpdate();
}
}
ttsCommit;
}
info('Orlando done');
}
private void readFilesFromSAPInbound()
{
SetEnumerator sE;
str filedate;
date fileDateLoc;
System.DateTime systemDateTime;
utcDateTime utcNow;
AweHOSPaymentTracker paymentTracker, paymentTrackerLoc;
boolean RecInster;
//filePath = @"\\Train-ax01\ax\AIF\I017\Inbound\Archive";
select *from filePathparameter where filePathparameter.FilePathType == FilePathType::Inbound &&
filePathparameter.MethodOfPayment == MethodOfPayment::SAP;
filePath = filePathparameter.FilePath;
this.GetTxtFiles();
sE = fileSet.getEnumerator();
while (sE.moveNext()) // loop through all files
{
filename = sE.current();
filedate = subStr(filename, 56,8);
fileDateLoc = str2Date(filedate, 321);
if (fileDateLoc != systemDate)
{
if (RecInster == false)
{
paymentTracker.TransDate = systemDate;
paymentTracker.PaymMode = 'SAP';
//paymentTracker.Inbound = Inbound::No;
paymentTracker.InboundProcessed = Processed::No;
//paymentTracker.Outbound = Outbound::None;
paymentTracker.OutboundProcessed = Processed::None;
paymentTracker.Processed = Processed::None;
paymentTracker.CompanyId = paymentTracker.dataAreaId;
paymentTracker.Remarks = '';
RecInster = true;
}
}
else if (fileDateLoc == systemDate)
{
info(strFmt("%1, %2", 'SAP', fileDateLoc));
paymentTracker.TransDate = systemDate;
paymentTracker.PaymMode = 'SAP';
//paymentTracker.Inbound = Inbound::Yes;
paymentTracker.InboundProcessed = Processed::Yes;
//paymentTracker.Outbound = Outbound::None;
paymentTracker.OutboundProcessed = Processed::None;
paymentTracker.Processed = Processed::None;
paymentTracker.CompanyId = paymentTracker.dataAreaId;
paymentTracker.Remarks = '';
}
}
select *from paymentTrackerLoc where paymentTrackerLoc.TransDate == paymentTracker.TransDate && paymentTrackerLoc.PaymMode == paymenttracker.PaymMode;
if (paymentTrackerLoc.TransDate != paymentTracker.TransDate && paymentTrackerLoc.PaymMode != paymentTracker.PaymMode)
{
paymentTracker.insert();
recIdSAP = paymentTracker.recid;
}
}
private void readFilesFromSAPOutbound()
{
SetEnumerator sE, sEOutbound;
str filedate;
date fileDateLoc;
System.DateTime systemDateTime;
//date systemDate;
utcDateTime utcNow;
boolean recInsert;
AweHOSPaymentTracker paymentTracker, paymentTrackerLoc;
//filePathOutbound = @"\\ame001.americanwaterservices.com\CIFS\Shared\Dynamics\Training\AX\SKS\PNC Lockbox\AWRL Lockbox\SAP\SK-Completed";
select *from filePathparameter where filePathparameter.FilePathType == FilePathType::Outbound && filePathparameter.MethodOfPayment == MethodOfPayment::SAP;
filePathOutbound = filePathparameter.FilePath;
this.GetXmlFiles();
sEOutbound = fileSet.getEnumerator();
while (sEOutbound.moveNext()) // loop through all files
{
filename = sEOutbound.current();
filedate = subStr(filename, 115,8);
fileDateLoc = str2Date(filedate, 321);
ttsBegin;
if (fileDateLoc != systemDate)
{
if (recInsert == false)
{
select forUpdate paymentTrackerLoc where paymentTrackerLoc.RecId == recIdSAP;
if (paymentTrackerLoc)
{
//paymentTrackerLoc.Outbound = Outbound::No;
paymentTrackerLoc.OutboundProcessed = Processed::No;
paymentTrackerLoc.update();
}
recInsert = true;
}
}
else if (fileDateLoc == systemDate)
{
select forUpdate paymentTrackerLoc where paymentTrackerLoc.RecId == recIdSAP;
if (paymentTrackerLoc)
{
//paymentTrackerLoc.Outbound = Outbound::Yes;
paymentTrackerLoc.OutboundProcessed = Processed::Yes;
paymentTrackerLoc.doUpdate();
}
}
ttsCommit;
}
info('SAP done');
}
public void run()
{
this.readFilesFromDirtecoryACH();
this.readFilesFromSAPInbound();
this.readFilesFromSAPOutbound();
this.readFilesFromOrlandoInbound();
this.readFilesFromOrlandoOutbound();
this.readFilesFromNashvilleInbound();
this.readFilesFromNashvilleOutbound();
this.readFilesFromEdisonLibertyInbound();
this.readFilesFromEdisonLibertyOutbound();
}
Public static AWEPaymentTrackerReadFilesFromDirectory construct()
{
return new AWEPaymentTrackerReadFilesFromDirectory();
}
public static ClassDescription description()
{
return 'HOS Customer Payment Tracker';
}
Public static void main(Args _args)
{
AWEPaymentTrackerReadFilesFromDirectory readFiles = AWEPaymentTrackerReadFilesFromDirectory::construct();
if (readFiles.prompt())
{
readFiles.run();
}
}
No comments:
Post a Comment