///
/// This method will sent email to sales invoice
///
public void sentEmailToInvoicePrint(RecId _jourRecId)
{
SalesInvoiceHeaderFooterTmp salesInvoiceHeaderTmpLoc;
SalesInvoiceTmp salesInvoiceTmpLoc;
CustInvoiceJour custInvoiceJourLoc1;
SalesLine salesLineLoc;
SalesId salesIdloc;
int countSalesId,countInvoiceSalesId;
CustInvoiceTrans custInvoiceTransLoc;
SalesId salesIDMap;
int countPrintInvoiceMap;
CustParameters custParameters;
select firstonly custParameters;
if (custParameters.ATNYLAInvoicePrintingNoYes == NoYes::Yes && custParameters.ATNYLAPrintEmail)
{
//retrieve from map
mapEnumerator = map.getEnumerator();
while (mapEnumerator.moveNext())
{
salesIDMap = mapEnumerator.currentKey();
countPrintInvoiceMap = mapEnumerator.currentValue();
if (countPrintInvoiceMap > 0 && salesIDMap)
{
select count(RecId) from custInvoiceTransLoc
join custInvoiceJourLoc1
where custInvoiceJourLoc1.salesid == salesIDMap
&& custInvoiceJourLoc1.InvoiceId == custInvoiceTransLoc.InvoiceId
&& custInvoiceJourLoc1.InvoiceDate == custInvoiceTransLoc.InvoiceDate;
countSalesId = custInvoiceTransLoc.RecId;
select firstonly custInvoiceTransLoc
join custInvoiceJourLoc1
where custInvoiceJourLoc1.salesid == salesIDMap
&& custInvoiceJourLoc1.InvoiceId == custInvoiceTransLoc.InvoiceId
&& custInvoiceJourLoc1.InvoiceDate == custInvoiceTransLoc.InvoiceDate;
salesIdloc = custInvoiceTransLoc.SalesId;
if (countSalesId != countPrintInvoiceMap && salesIdloc)
{
ATNYLAEmailer::sendSMTPEmail(custParameters.ATNYLAPrintEmail,strFmt('@ATNYLA:MissInvLine',salesIdloc),strFmt('@ATNYLA:SOMissingPrint',salesIdloc));
}
}
}
}
}
class ATNYLAProgramProductsTableImport extends RunBaseBatch
{
DialogRunbase dialog;
DialogField dialogDefinitionGroupUpdate;
DMFDefinitionGroupName definitionGroupUpdate;
Filename filename;
System.IO.Stream fileStream;
SharedServiceUnitFileID fileID;
DMFDefinitionGroupName definitionGroupName;
#define.definitionGroupName("Program products import")
#define.CurrentVersion(3)
#localmacro.CurrentList
definitionGroupUpdate,
filename, fileID
#endmacro
private const str OkButtonName = 'OkButton';
private const str FileUploadName = 'FileUpload';
///
///
///
public boolean canGoBatch()
{
return true;
}
///
///
///
protected boolean canGoBatchJournal()
{
return true;
}
///
/// Returns a class that contains the methods that are described by the RunBaseDialogable
/// interface.
///
///
/// A class that contains the methods that are described by the RunBaseDialogable interface.
///
///
/// A dialog can be either built by using the Dialog class or by using a class that is created
/// in the Application Object Tree (AOT).
///
public Object dialog()
{
DialogGroup dialogGroup;
FormBuildControl formBuildControl;
FileUploadBuild dialogFileUpload;
dialog = new DialogRunbase(ATNYLAProgramProductsTableImport::description(), this);
dialogDefinitionGroupUpdate = dialog.addFieldValue(extendedTypeStr(DMFDefinitionGroupName), definitionGroupUpdate);
dialogDefinitionGroupUpdate.registerOverrideMethod(methodStr(FormStringControl, lookup), methodStr(ATNYLAProgramProductsTableImport, lookUpDefinitionGroup), this);
dialogDefinitionGroupUpdate.value(#definitionGroupName);
dialogGroup = dialog.addGroup(ATNYLAProgramProductsTableImport::description());
formBuildControl = dialog.formBuildDesign().control(dialogGroup.name());
dialogFileUpload = formBuildControl.addControlEx(classstr(FileUpload), FileUploadName);
dialogFileUpload.style(FileUploadStyle::MinimalWithFilename);
dialogFileUpload.fileTypesAccepted('.xlsx,.xls,.xlsm');
dialogFileUpload.baseFileUploadStrategyClassName(classstr(FileUploadTemporaryStorageStrategy));
dialogFileUpload.fileNameLabel("@SYS308842");
return dialog;
}
///
/// Looks up the definition group name.
///
///
/// The look up control.
///
public void lookUpDefinitionGroup(FormStringControl _control)
{
Query query;
QueryBuildDataSource qbds;
SysTableLookup lookup;
container con;
str rangeValue;
DMFDefinitionGroupEntity definitionGroupEntity;
#define.Import('Program products')
while select DefinitionGroup from definitionGroupEntity
where definitionGroupEntity.Entity == #Import
&& definitionGroupEntity.DefinitionGroup == #definitionGroupName
{
con += definitionGroupEntity.DefinitionGroup;
}
rangeValue = con2Str(con, ',');
query = new Query();
qbds = query.addDataSource(tableNum(DMFDefinitionGroup));
qbds.addRange(fieldNum(DMFDefinitionGroup, DefinitionGroupName)).value(rangeValue);
lookup = SysTableLookup::newParameters(tableNum(DMFDefinitionGroup), _control, true);
lookup.parmQuery(query);
lookup.addLookupField(fieldNum(DMFDefinitionGroup, DefinitionGroupName), true);
lookup.addLookupField(fieldNum(DMFDefinitionGroup, Description));
lookup.performFormLookup();
}
///
/// Disables the dialog Ok button until the file upload is complete.
///
/// The Runbase dialog object.
public void dialogPostRun(DialogRunbase _dialog)
{
FileUpload fileUpload = this.getFormControl(_dialog, FileUploadName);
fileUpload.notifyUploadCompleted += eventhandler(this.uploadCompleted);
this.setDialogOkButtonEnabled(_dialog, false);
}
///
/// Displays the summary of the execution
///
public void executionStatus()
{
DMFDefinitionGroupExecution definitionGroupExecution;
DMFExecutionSummaryStatus summaryStatus;
DMFExecution execution;
select firstonly ExecutionId, NoOfRecords, NumOfTargetNew, NumOfTargetUpdated from definitionGroupExecution
order by CreatedDateTime desc
where definitionGroupExecution.DefinitionGroup == #definitionGroupName;
execution = DMFExecution::find(definitionGroupExecution.ExecutionId);
summaryStatus = execution.GetExecutionSummaryStatus();
info(strFmt("@SYS90632",DateTimeUtil::applyTimeZoneOffset(DateTimeUtil::utcNow(), DateTimeUtil::getUserPreferredTimeZone())));
info(strfmt("@ATNYLA:FileReadFrom", filename));
info(strfmt("@ATNYLA:RowsInserted", definitionGroupExecution.NumOfTargetNew));
info(strfmt("@ATNYLA:RecordsUpdated", definitionGroupExecution.NumOfTargetUpdated));
info(strFmt("@ATNYLA:ImportStatus", DMFExecutionStatusHelper::GetExecutionSummaryStatusText(summaryStatus)));
info(strFmt("@ATNYLA:ExecutionId", definitionGroupExecution.ExecutionId));
info("@ATNYLA:Importcompleted");
}
///
/// After the file has been uploaded, the Ok button is enabled.
///
protected void uploadCompleted()
{
FileUpload fileUpload = this.getFormControl(dialog, FileUploadName);
fileUpload.notifyUploadCompleted -= eventhandler(this.UploadCompleted);
filename = fileUpload.fileName();
this.setDialogOkButtonEnabled(dialog, true);
}
///
/// Enables or disables the dialog Ok button.
///
/// The Runbase dialog object.
/// Indicates to enable or disable the Ok button.
protected void setDialogOkButtonEnabled(DialogRunbase _dialog, boolean _isEnabled)
{
FormControl okButtonControl = this.getFormControl(_dialog, OkButtonName);
if (okButtonControl)
{
okButtonControl.enabled(_isEnabled);
}
}
///
/// Gets the form control
///
/// Returns the form control
protected FormControl getFormControl(DialogRunbase _dialog, str _controlName)
{
return _dialog.formRun().control(_dialog.formRun().controlId( _controlName));
}
///
/// Gets the user input values from dialog
///
/// /// Returns True/False
public boolean getFromDialog()
{
boolean ret;
ret = super();
definitionGroupUpdate = dialogDefinitionGroupUpdate.value();
FileUpload fileUploadControl = this.getFormControl(dialog, FileUploadName);
FileUploadTemporaryStorageResult fileUploadResult = fileUploadControl.getFileUploadResult();
if (fileUploadResult != null && fileUploadResult.getUploadStatus())
{
fileID = fileUploadResult.getFileId();
}
return ret;
}
///
/// Contains the code that does the actual job of the class.
///
public void run()
{
DMFExecutionId executionId;
DMFDefinitionGroup definitionGroup;
DMFDefinitionGroupEntity definitionGroupEntity;
boolean executeTargetDuringInitialImport;
DMFDefinitionGroupExecution definitionGroupExecution;
DMFExecutionSummaryStatus summaryStatus;
DMFExecution execution;
try
{
definitionGroup = ATNYLAProgramProductsTableImport::findDMFDefinitionGroup(definitionGroupUpdate);
ATNYLAProgramProductsTableImport::applyTransforms(fileID, definitionGroup);
definitionGroupEntity = ATNYLAProgramProductsTableImport::findDMFDefinitionGroupEntity(definitionGroup);
executionId = DMFUtil::setupNewExecution(definitionGroup.DefinitionGroupName);
// Determine if source to target should happen on initial import based on if we are in batch or not.
executeTargetDuringInitialImport = !this.parmInBatch();
// Find execution
definitionGroupExecution = DMFDefinitionGroupExecution::find(definitionGroup.DefinitionGroupName,
definitionGroupEntity.Entity, executionId, true);
summaryStatus = definitionGroupExecution.GetExecutionSummaryStatus();
execution = DMFExecution::find(definitionGroupExecution.ExecutionId);
//To showing info related to count
definitionGroupExecution.FilePath = fileID;
definitionGroupExecution.IsTransformed = NoYes::Yes;
definitionGroupExecution.ExecuteTargetStep = executeTargetDuringInitialImport;
definitionGroupExecution.update();
DMFQuickImportExport::doPGImport(definitionGroup.DefinitionGroupName, executionId, executeTargetDuringInitialImport);
// If we still need to move from source to target, kick off that process now.
if (!executeTargetDuringInitialImport)
{
DMFDefinitionGroupExecution executionSourceToTarget;
update_recordset executionSourceToTarget
setting IsSelected = NoYes::Yes
where executionSourceToTarget.ExecutionId == executionId;
DMFWriteExecutionParameters executionParameters = DMFWriteExecutionParameters::construct();
executionParameters.parmDefinitionGroup(definitionGroup.DefinitionGroupName);
executionParameters.parmsourceTarget(DMFSourceTarget::Source);
executionParameters.parmSelectedData(NoYes::No);
executionParameters.parmErrorStatus(NoYes::No);
executionParameters.parmSkipFormNavigation(NoYes::Yes);
DMFExecution dmfExecution = DMFExecution::find(executionId, true);
Args args = new Args();
args.record(dmfExecution);
args.parmObject(executionParameters);
args.parmEnum(NoYes::No);
new MenuFunction(menuItemActionStr(DMFEntityWriterBatch), MenuItemType::Action).run(args);
}
this.executionStatus();
}
catch(Exception::Error)
{
info(strFmt("%1",Exception::Error));
}
}
///
///
///
public boolean runsImpersonated()
{
return true;
}
///
/// Packs the state of the object
///
///
/// Returns the packed container
///
public container pack()
{
return [#CurrentVersion, #CurrentList];
}
///
/// Unpacks the received contaienr object
///
/// Container with the packed status
///
/// Returns the packed container
///
public boolean unpack(container _packedClass)
{
Integer version = conPeek(_packedClass, 1);
switch (version)
{
case #CurrentVersion:
[version, #CurrentList] = _packedClass;
break;
default:
return false;
}
return true;
}
///
/// Validates the user input information
///
/// The caller object
///
/// Returns True/False
///
public boolean validate(Object _calledFrom = null)
{
boolean ret = true;
if (!definitionGroupUpdate)
{
ret = checkFailed("@DMF1432");
}
if (!filename)
{
ret = checkFailed("@SYS18624");
}
return ret;
}
///
/// Constructs the ATNYLAProductUOMConversionsImport object
///
/// Returns the ATNYLAProductUOMConversionsImport object
public static ATNYLAProgramProductsTableImport construct()
{
return new ATNYLAProgramProductsTableImport();
}
///
/// Provides caption for the dialog
///
/// Reutrns the caption of the dialog
public static ClassDescription description()
{
return ("Program products import");
}
///
/// Provides the entry point for the ATNYLAPurchaseOrdersImportInsertDialog dialog class
///
///
public static void main(Args args)
{
ATNYLAProgramProductsTableImport programProductsTableImport;
programProductsTableImport = ATNYLAProgramProductsTableImport::construct();
if (programProductsTableImport.prompt())
{
programProductsTableImport.runOperation();
}
}
///
///
///
protected boolean canRunInNewSession()
{
return false;
}
///
///
///
private static DMFLocalFilePath applyTransforms(SharedServiceUnitFileID _uploadedStatement, DMFDefinitionGroup definitionGroup)
{
DMFDefinitionGroupEntity definitionGroupEntity = ATNYLAProgramProductsTableImport::findDMFDefinitionGroupEntity(definitionGroup);
DMFExecutionId executionId = DMFUtil::setupNewExecution(definitionGroup.DefinitionGroupName);
DMFDefinitionGroupExecution execution = DMFDefinitionGroupExecution::find(
definitionGroup.DefinitionGroupName,
definitionGroupEntity.Entity,
executionId,
true);
execution.IsTransformed = NoYes::No;
DMFLocalFilePath filePath = execution.applyTransforms(_uploadedStatement);
DMFExecution e = DMFExecution::find(executionId, true);
e.delete();
return filePath;
}
///
///
///
private static DMFDefinitionGroupEntity findDMFDefinitionGroupEntity(DMFDefinitionGroup _definitionGroup)
{
DMFDefinitionGroupEntity definitionGroupEntity;
DMFEntity dmfEntity;
select firstonly RecId, Entity from definitionGroupEntity exists join dmfEntity
where definitionGroupEntity.DefinitionGroup == _definitionGroup.DefinitionGroupName
&& dmfEntity.EntityName == definitionGroupEntity.Entity
&& dmfEntity.TargetEntity == dataentityviewstr(ATNYLAProgramProductsTableEntity);
if (!definitionGroupEntity)
{
throw error(strFmt("@DMF:DMFNoEntityExists", _definitionGroup.DefinitionGroupName));
}
return definitionGroupEntity;
}
///
///
///
private static DMFDefinitionGroup findDMFDefinitionGroup(DMFDefinitionGroupName definitionGroupName)
{
DMFDefinitionGroup definitionGroup;
select firstonly definitionGroup
where definitionGroup.DefinitionGroupName == definitionGroupName; //PurchParameters::find().ATNYLAProcessingGroupDisplayUpdate;//DMF import data project
return definitionGroup;
}
}