using Microsoft.Azure;
using Microsoft.WindowsAzure.Storage;
using Microsoft.WindowsAzure.Storage.Blob;
using Microsoft.WindowsAzure.Storage.Blob.CloudBlobContainer;
using Microsoft.WindowsAzure.Storage.File;
using System.IO.Stream;
using System.IO.Compression;
Public class W_BulkCreditDebitNoteService
{
TransDate fromDateVal, toDateVal,JournalDate;
str
Segment,IsClassificationApplicable,Email,CRN_DRN_Number,Account,voucher;
WDebiteCreditNote debitCreditVal;
WSalesPurchaseEnum SalesPurchase;
str responseMessage;
Voucher Note_Type;
VendAccount vendAccountVal;
CustAccount custAccountVal, linkedBPVal;
str CustomerName;
Str60 Note;
/// <summary>
/// Processing Report.
/// </summary>
/// <param name =
"Parameters"> W_BulkCreditDebitNoteRequestContract</param>
public W_BulkCreditDebitNoteResponseContract processReport(
W_BulkCreditDebitNoteRequestContract Parameters)
{
RefRecId ledgerCustomerRefId;
dimensionAttributeValueCombination dimAttributeValueCombinationCust;
CustTable custTableQry;
DirPartyPostalAddressView DirPartyPostalAddressView;
TAXREGISTRATIONNUMBERS_IN TAXREGISTRATIONNUMBERS_IN;
WQRCodeIRNEWBAPIData qRCodeIRNEWBAPIData;
MenuFunction menuFunctionBulkOld;
WSalesPurchaseEnum salesPurchaseVal;
SystemParameters systemParameters;
//Voucher Note_Type;
LedgerJournalTrans
_LedgerJournalTrans;
LedgerJournalTable
_LedgerJournalTable;
DimensionAttributeValueCombination
_DimensionAttributeValueCombination;
CustTable
_CustTable;
CustAccount CustAccountValue;
LogisticsLocation LogisticsLocation;
TaxInformation_IN TaxInformation_IN;
VendTable
_VendTable,vendTable;
VendAccount vendAccountValue;
smmSegmentId segmentIdVal;
CustClassificationId custClassificationIdVal;
NoYes custClassificationChkVal;
boolean RecExists =
false;
boolean isReportGenerated;
responseMessage
= '';
IsClassificationApplicable
= Parameters.parmIsClassificationApplicable();
CRN_DRN_Number
= Parameters.parmCRN_DRN_Number();
Email
= Parameters.parmemailAddress();
Map maplist = new Map(Types::String,Types::Class);
void getstream()
{
MapEnumerator enumerator
= maplist.getEnumerator();
System.IO.MemoryStream
zipStream1 = new System.IO.MemoryStream();
{
using (System.IO.Compression.ZipArchive archive =
new System.IO.Compression.ZipArchive(zipStream1, System.IO.Compression.ZipArchiveMode::Create,
true))
{
while(enumerator.moveNext())
{
System.IO.Compression.ZipArchiveEntry dataFileEntry
= archive.CreateEntry(enumerator.currentKey()
+".Pdf");
using
(System.IO.Stream dataFileEntryStream = dataFileEntry.Open())
{
System.IO.MemoryStream stream
= enumerator.currentValue();
stream.Seek(0, System.IO.SeekOrigin::Begin);
stream.CopyTo(dataFileEntryStream);
}
}
}
if (isReportGenerated)
{
if(custAccountVal != "*")
{
this.sendEmail(zipStream1,custAccountVal);
}
if(linkedBPVal != "*")
{
this.sendEmail(zipStream1,linkedBPVal);
}
}
}
}
W_BulkCreditDebitNoteResponseContract Contract
= new W_BulkCreditDebitNoteResponseContract();
changecompany(Parameters.parmDataArea())
{
fromDateVal
= Parameters.parmFromdate();
toDateVal
= Parameters.parmTodate();
custAccountVal
= Parameters.parmCustAccount();
linkedBPVal
= Parameters.parmCustAccountLoc();
debitCreditVal
= FormJsonSerializer::deserializeValue(Types::Enum, Parameters.parmJournaltype(), enumNum(
WDebiteCreditNote));
salesPurchaseVal
= FormJsonSerializer::deserializeValue(Types::Enum, Parameters.parmSalesPurchase(), enumNum(
WSalesPurchaseEnum));
segmentIdVal
= (Parameters.parmSegment() == "" ? "*"
:Parameters.parmSegment());
custClassificationIdVal
= Parameters.parmIsClassificationApplicable();
custClassificationChkVal
= NoYes::No;
vendAccountVal
=Parameters.parmVendAccount();
if (!Email)
{
throw Error("Please provide email address.");
}
if(salesPurchaseVal == 255)
{
throw Error("Please provide either Sales or Purchase.");
}
if(debitCreditVal == 255)
{
throw Error("Please provide
either CreditNote or DebitNote.");
}
if(!linkedBPVal &&
!custAccountVal && salesPurchaseVal== WSalesPurchaseEnum::Sales
&& !Parameters.parmCRN_DRN_Number())
{
throw Error("Please provide either LinkedBP or
Customer.");
}
CustTable CustTable;
if(Parameters.parmCustAccount() ||Parameters.parmCustAccountLoc())
{
select CustTable where
(CustTable.AccountNum == linkedBPVal || CustTable.AccountNum == custAccountVal);
CustomerName = CustTable.name();
Account = CustTable.AccountNum;
if(!CustTable.recid)
{
throw Error ('Please provide existing customer ');
}
if(Parameters.parmSegment() == "Non_Trade"
&& linkedBPVal)
{
throw Error("Please Provide customers only");
}
}
else if(!custAccountVal && Parameters.parmSegment() ==
"Non_Trade")
{
throw Error("Please Provide customers ");
}
select systemParameters
where systemParameters. WIntegrationDataArea == Parameters.parmDataArea();
if(!fromDateVal)
{
throw error('Please enter from date');
}
if(!toDateVal)
{
throw error('Please enter to date');
}
if(fromDateVal > toDateVal)
{
throw error('To date should not be greater than equal to From date !');
}
if(toDateVal <= systemParameters. WEInvoiceDate)
{
throw error('Please select period which is either before IRN applicable or
after IRN applicable!');
}
if(salesPurchaseVal == WSalesPurchaseEnum::Sales)
{
if(!custAccountVal)
{
custAccountVal =
"*";
}
if(!linkedBPVal)
{
linkedBPVal =
"*";
}
if(debitCreditVal == WDebiteCreditNote::CreditNote)
{
Note_Type =
"*CN*";
}
else
{
Note_Type =
"*DN*";
}
if(custClassificationChkVal == NoYes::No)
{
custClassificationIdVal =
"*";
}
while select _LedgerJournalTrans
join _LedgerJournalTable
join _DimensionAttributeValueCombination
Join _CustTable
order by _CustTable.AccountNum
where _LedgerJournalTrans.JournalNum == _LedgerJournalTable.JournalNum
&& _LedgerJournalTable.Posted == NoYes::Yes
&& _LedgerJournalTrans.LedgerDimension ==
_DimensionAttributeValueCombination.RecId
&& _DimensionAttributeValueCombination.DisplayValue ==
_CustTable.AccountNum
&& (_LedgerJournalTrans.TransDate >= fromDateVal
&& _LedgerJournalTrans.TransDate <= toDateVal
||_LedgerJournalTrans.Voucher == CRN_DRN_Number)
&& _LedgerJournalTrans.AccountType == LedgerJournalACType::Cust
&& _CustTable. WLinkedBP like linkedBPVal
&& _LedgerJournalTable.JournalName like Note_Type
&& _CustTable.SegmentId like segmentIdVal
&& _CustTable.CustClassificationId like custClassificationIdVal
&& _CustTable.AccountNum like custAccountVal
{
CustomerName = _CustTable.name();
if(systemParameters. WDigitalSignApplicability == NoYes::No)
{
throw Error("Can't print bulk report as digital sign applicability is not
enabled.");
}
ledgerCustomerRefId
=(((_LedgerJournalTrans.AccountType == LedgerJournalACType::Cust)
||
(_LedgerJournalTrans.AccountType == LedgerJournalACType::Vend))
?
_LedgerJournalTrans.LedgerDimension :
((_LedgerJournalTrans.OffsetAccountType == LedgerJournalACType::Cust)
||
(_LedgerJournalTrans.OffsetAccountType == LedgerJournalACType::Vend))?
_LedgerJournalTrans.OffsetLedgerDimension:
_LedgerJournalTrans.LedgerDimension);
select firstonly DisplayValue from dimAttributeValueCombinationCust
where dimAttributeValueCombinationCust.RecId == ledgerCustomerRefId;
CustAccountValue = CustTable::find(dimAttributeValueCombinationCust.DisplayValue).AccountNum;
select custTableQry join DirPartyPostalAddressView
join LogisticsLocation
join TAXINFORMATION_IN
join REGISTRATIONNUMBER from TAXREGISTRATIONNUMBERS_IN
where custTableQry.Party == DirPartyPostalAddressView.Party && custTableQry.AccountNum == CustAccountValue
&& LogisticsLocation.RecId == DirPartyPostalAddressView.Location && DirPartyPostalAddressView.IsPrimary==NoYes::Yes
&& LogisticsLocation.RecId ==TAXINFORMATION_IN.REGISTRATIONLOCATION
&& TAXINFORMATION_IN.IsPrimary==NoYes::Yes
&& TAXINFORMATION_IN.GSTIN == TAXREGISTRATIONNUMBERS_IN.RECID;
TransTaxInformation TransTaxInformation;
TransTaxInformationRelationView TransTaxInformationRelationView;
select HSNCodeTable,ServiceAccountingCodeTable from TransTaxInformation
exists join TransTaxInformationRelationView
where TransTaxInformationRelationView.TransactionRefRecId ==
_LedgerJournalTrans.RecId &&
TransTaxInformationRelationView.TransactionRefTableId == tableNum(LedgerJournalTrans)&&
TransTaxInformationRelationView.TransTaxInformationRefRecId == TransTaxInformation.RecId;
if(TAXREGISTRATIONNUMBERS_IN.RegistrationNumber != "" &&
(HSNCodeTable_IN::find(TransTaxInformation.HSNCodeTable).code != ""
|| ServiceAccountingCodeTable_IN::find(TransTaxInformation.ServiceAccountingCodeTable).SAC
!= ""))
{
select qRCodeIRNEWBAPIData
where qRCodeIRNEWBAPIData.DocumentNumber ==
_LedgerJournalTrans.Voucher
&& (qRCodeIRNEWBAPIData.APIDocType == WAPIDocumentType::CreditNote
|| qRCodeIRNEWBAPIData.APIDocType == WAPIDocumentType::DebiteNote
|| qRCodeIRNEWBAPIData.APIDocType == WAPIDocumentType::TaxInvoice);
if(qRCodeIRNEWBAPIData.IRNNumber == "")
{
Note = (strFmt("IRN number not yet generated for voucher
%1.",_LedgerJournalTrans.Voucher));
continue;
}
else
{
if(debitCreditVal == WDebiteCreditNote::CreditNote)
{
RecExists =
true;
Args argsSingle
= new Args();
System.IO.Stream stream;
stream = this.generateReportCRN(argsSingle,_LedgerJournalTrans,ssrsReportStr(
WCreditDebitReport, CreditDebitPrecisionDesignShortageCNDN));
isReportGenerated =
true;
maplist.add(_LedgerJournalTrans.Voucher,Stream);
}
if(debitCreditVal == WDebiteCreditNote::DebitNote)
{
RecExists =
true;
Args argsSingle =
new Args();
argsSingle.record(_LedgerJournalTrans);
System.IO.Stream Stream;
Stream=this.generateReportCRN(argsSingle,_LedgerJournalTrans,ssrsReportStr( WCreditDebitReport, CreditDebitPrecisionDesignShortageCNDN));
isReportGenerated =
true;
maplist.add(_LedgerJournalTrans.Voucher,Stream);
}
}
}
else
{
if(debitCreditVal == WDebiteCreditNote::CreditNote)
{
RecExists =
true;
Args argsSingle =
new Args();
System.IO.Stream Stream;
argsSingle.record(_LedgerJournalTrans);
Stream = this.generateReportCRN(argsSingle,_LedgerJournalTrans,ssrsReportStr(
WCreditDebitReport, CreditDebitPrecisionDesignShortageCNDN));
isReportGenerated =
true;
maplist.add(_LedgerJournalTrans.Voucher,Stream);
}
if(debitCreditVal == WDebiteCreditNote::DebitNote)
{
RecExists =
true;
Args argsSingle =
new Args();
argsSingle.record(_LedgerJournalTrans);
System.IO.Stream Stream;
Stream =this.generateReportCRN(argsSingle,_LedgerJournalTrans,ssrsReportStr( WCreditDebitReport, CreditDebitPrecisionDesignShortageCNDN));
isReportGenerated =
true;
maplist.add(_LedgerJournalTrans.Voucher,Stream);
}
}
}
}
else
{
if(!vendAccountVal)
{
throw error('Please enter Vendor Account Number');
}
else
{
Account = vendAccountVal;
}
if(debitCreditVal == WDebiteCreditNote::CreditNote)
{
Note_Type =
"*CN*";
}
else
{
Note_Type =
"*DN*";
}
while select _LedgerJournalTrans
join _LedgerJournalTable
join _DimensionAttributeValueCombination
Join _VendTable
where _LedgerJournalTrans.JournalNum ==
_LedgerJournalTable.JournalNum
&& _LedgerJournalTable.Posted == NoYes::Yes
&& _LedgerJournalTrans.LedgerDimension ==
_DimensionAttributeValueCombination.RecId
&& _DimensionAttributeValueCombination.DisplayValue ==
_VendTable.AccountNum
&& (_LedgerJournalTrans.TransDate >= fromDateVal
&& _LedgerJournalTrans.TransDate <= toDateVal
|| _LedgerJournalTrans.Voucher == CRN_DRN_Number)
&&
_LedgerJournalTrans.AccountType == LedgerJournalACType::Vend
&& _VendTable.AccountNum like vendAccountVal
&& _LedgerJournalTable.JournalName like Note_Type
{
if(systemParameters. WDigitalSignApplicability == NoYes::No)
{
throw Error("Can't print bulk report as digital sign applicability is not
enabled.");
}
ledgerCustomerRefId
=(((_LedgerJournalTrans.AccountType == LedgerJournalACType::Cust)
||
(_LedgerJournalTrans.AccountType == LedgerJournalACType::Vend))
?
_LedgerJournalTrans.LedgerDimension :
((_LedgerJournalTrans.OffsetAccountType == LedgerJournalACType::Cust)
||
(_LedgerJournalTrans.OffsetAccountType == LedgerJournalACType::Vend))?
_LedgerJournalTrans.OffsetLedgerDimension:
_LedgerJournalTrans.LedgerDimension);
select firstonly DisplayValue from dimAttributeValueCombinationCust
where dimAttributeValueCombinationCust.RecId == ledgerCustomerRefId;
vendAccountValue = VendTable::find(dimAttributeValueCombinationCust.DisplayValue).AccountNum;
select vendTable join DirPartyPostalAddressView
join LogisticsLocation
join TAXINFORMATION_IN
join REGISTRATIONNUMBER from TAXREGISTRATIONNUMBERS_IN
where vendTable.Party == DirPartyPostalAddressView.Party && vendTable.AccountNum == vendAccountValue
&& LogisticsLocation.RecId == DirPartyPostalAddressView.Location && DirPartyPostalAddressView.IsPrimary==NoYes::Yes
&& LogisticsLocation.RecId ==TAXINFORMATION_IN.REGISTRATIONLOCATION
&& TAXINFORMATION_IN.IsPrimary==NoYes::Yes
&& TAXINFORMATION_IN.GSTIN ==
TAXREGISTRATIONNUMBERS_IN.RECID;
TransTaxInformation TransTaxInformation;
TransTaxInformationRelationView TransTaxInformationRelationView;
select HSNCodeTable,ServiceAccountingCodeTable from TransTaxInformation
exists join TransTaxInformationRelationView
where TransTaxInformationRelationView.TransactionRefRecId ==
_LedgerJournalTrans.RecId &&
TransTaxInformationRelationView.TransactionRefTableId == tableNum(LedgerJournalTrans)&&
TransTaxInformationRelationView.TransTaxInformationRefRecId == TransTaxInformation.RecId;
if(TAXREGISTRATIONNUMBERS_IN.RegistrationNumber != "" &&
(HSNCodeTable_IN::find(TransTaxInformation.HSNCodeTable).code != ""
|| ServiceAccountingCodeTable_IN::find(TransTaxInformation.ServiceAccountingCodeTable).SAC
!= ""))
{
select qRCodeIRNEWBAPIData
where qRCodeIRNEWBAPIData.DocumentNumber == _LedgerJournalTrans.Voucher
&& (qRCodeIRNEWBAPIData.APIDocType == WAPIDocumentType::CreditNote
|| qRCodeIRNEWBAPIData.APIDocType == WAPIDocumentType::DebiteNote
|| qRCodeIRNEWBAPIData.APIDocType == WAPIDocumentType::TaxInvoice);
if(qRCodeIRNEWBAPIData.IRNNumber == "")
{
Note =(strFmt("IRN number not yet generated for voucher %1.",_LedgerJournalTrans.Voucher));
continue;
}
else
{
if(debitCreditVal == WDebiteCreditNote::CreditNote)
{
RecExists =
true;
Args argsSingle =
new Args();
argsSingle.record(_LedgerJournalTrans);
System.IO.Stream Stream;
Stream = this.generateReportCRN(argsSingle,_LedgerJournalTrans,ssrsReportStr(
WCreditDebitReport, CreditDebitPrecisionDesignPurchase));
isReportGenerated =
true;
maplist.add(_LedgerJournalTrans.Voucher,Stream);
}
if(debitCreditVal == WDebiteCreditNote::DebitNote)
{
RecExists =
true;
System.IO.Stream Streamloc;
Args argsSingle =
new Args();
argsSingle.record(_LedgerJournalTrans);
Streamloc = this.generateReportCRN(argsSingle,_LedgerJournalTrans,ssrsReportStr(
WCreditDebitReport, CreditDebitPrecisionDesignPurchase));
isReportGenerated =
true;
maplist.add(_LedgerJournalTrans.Voucher,Streamloc);
}
}
}
else
{
if(debitCreditVal == WDebiteCreditNote::CreditNote)
{
RecExists =
true;
Args argsSingle =
new Args();
argsSingle.record(_LedgerJournalTrans);
System.IO.Stream
Stream;
Stream = this.generateReportCRN(argsSingle,_LedgerJournalTrans,ssrsReportStr(
WCreditDebitReport, CreditDebitPrecisionDesignPurchase));
isReportGenerated =
true;
maplist.add(_LedgerJournalTrans.Voucher,Stream);
}
if(debitCreditVal == WDebiteCreditNote::DebitNote)
{
RecExists =
true;
Args argsSingle =
new Args();
argsSingle.record(_LedgerJournalTrans);
System.IO.Stream
Stream;
this.generateReportCRN(argsSingle,_LedgerJournalTrans,ssrsReportStr(
WCreditDebitReport, CreditDebitPrecisionDesignPurchase));
isReportGenerated =
true;
maplist.add(_LedgerJournalTrans.Voucher,Stream);
}
}
}
}
if (isReportGenerated)
{
getstream();
}
if(!RecExists)
{
responseMessage ="No
record found for the selected criteria";
}
}
Contract.parmMessage(responseMessage);
return
Contract;
}
/// <summary>
/// Generate Report.
/// </summary>
/// <param name =
"_args">Agrs</param>
/// <param name =
"_LedgerJournalTrans">LedgerJournal Table</param>
/// <param name =
"reportName">Report Name</param>
public System.IO.Stream generateReportCRN(Args _args ,LedgerJournalTrans
_LedgerJournalTrans, str reportName)
{
str signSettingName;
str reportbyteString;
VendParameters
parameters = VendParameters::find();
//str
Filename
= strFmt("%1_%2_%3",
debitCreditVal,_LedgerJournalTrans.Voucher,_LedgerJournalTrans.TransDate);
Filename Filename;
//SrsReportRunController controller =
new SrsReportRunController();
WCreditDebitControler
controller = new WCreditDebitControler();
boolean
uploaded= false;
SRSPrintDestinationSettings
settings;
Array arrayFiles;
System.Byte[] reportBytes =
new System.Byte[0]();
SRSProxy srsProxy;
SRSReportRunService srsReportRunService =
new SrsReportRunService();
Microsoft.Dynamics.AX.Framework.Reporting.Shared.ReportingService.ParameterValue[] parameterValueArray;
Map reportParametersMap;
SRSReportExecutionInfo executionInfo
= new SRSReportExecutionInfo();
WCreditDebitContract contract
= new WCreditDebitContract();
voucher
= _LedgerJournalTrans.Voucher;
JournalDate
= _LedgerJournalTrans.TransDate;
dimensionAttributeValueCombination dimensionAttributeValueCombinationCust;
if(reportName == " WCreditDebitReport.CreditDebitPrecisionDesignShortageCNDN")
{
Filename
= strfmt("CN_%1",_LedgerJournalTrans.Voucher);
signSettingName =
"CreditNote";
}
else
if(reportName == " WCreditDebitReport.CreditDebitPrecisionDesignShortage")
{
Filename
= strfmt("TI_%1",_LedgerJournalTrans.Voucher);
signSettingName =
"TaxInvoice";
}
else
if(reportName == " WCreditDebitReport.CreditDebitPrecisionDesignPurchase")
{
Filename
= strfmt("DN_%1",_LedgerJournalTrans.Voucher);
signSettingName =
"DebitNote";
}
contract.parmLedgerJournalTableRecId(_LedgerJournalTrans.RecId);
contract.parmVoucherId(_LedgerJournalTrans.Voucher);
controller.parmArgs(_args);
controller.parmReportName(reportName);
controller.parmShowDialog(false);
controller.parmLoadFromSysLastValue(false);
controller.parmReportContract().parmRdpContract(contract);
settings = controller.parmReportContract().parmPrintSettings();
settings.printMediumType(SRSPrintMediumType::File);
settings.fileName(Filename);
settings.fileFormat(SRSReportFileFormat::PDF);
controller.parmReportContract().parmReportServerConfig(SRSConfiguration::getDefaultServerConfiguration());
controller.parmReportContract().parmReportExecutionInfo(executionInfo);
srsReportRunService.getReportDataContract(controller.parmreportcontract().parmReportName());
srsReportRunService.preRunReport(controller.parmreportcontract());
reportParametersMap = srsReportRunService.createParamMapFromContract(controller.parmReportContract());
parameterValueArray = SrsReportRunUtil::getParameterValueArray(reportParametersMap);
srsProxy = SRSProxy::constructWithConfiguration(controller.parmReportContract().parmReportServerConfig());
reportBytes = srsproxy.renderReportToByteArray(controller.parmreportcontract().parmreportpath(),
parameterValueArray,
settings.fileFormat(),
settings.deviceinfo());
reportbyteString = System.Convert::ToBase64String(reportBytes);
System.IO.MemoryStream stream;
select firstonly DisplayValue from dimensionAttributeValueCombinationCust
where dimensionAttributeValueCombinationCust.RecId ==
_LedgerJournalTrans.LedgerDimension;
if(_LedgerJournalTrans. WDigitalSignUploaded == NoYes::No)
{
WDigitalSignGenericClass WDigitalSignGenericClass=new WDigitalSignGenericClass();
uploaded = WDigitalSignGenericClass.runDigitalSign(reportbyteString,
Filename, signSettingName);
if(uploaded)
{
_LedgerJournalTrans.selectForUpdate(true);
ttsbegin;
_LedgerJournalTrans. WDigitalSignUploaded = NoYes::Yes;
_LedgerJournalTrans.doUpdate();
ttscommit;
stream = this.downloadfileFromBlobContainer(Filename+".pdf",
signSettingName,dimensionAttributeValueCombinationCust.DisplayValue);
}
}
else
{
stream = this.downloadfileFromBlobContainer(Filename+".pdf",
signSettingName,dimensionAttributeValueCombinationCust.DisplayValue);
}
int i;
i++;
container con
;
conIns(con,i,stream);
return
stream;
}
/// <summary>
/// To Download report from BLOB.
/// </summary>
/// <param name =
"fileName">File Name</param>
/// <param name =
"fileType">File Type/param>
/// <param name =
"_CustVendCode">CustAccount/param>
public System.IO.Stream downloadfileFromBlobContainer(str fileName,
str fileType, str60 _CustVendCode)
{
str connectionString;
CloudBlobClient cloudBlobClient;
CloudStorageAccount cloudStorageAccount;
CloudBlobDirectory cloudBlobDirectory;
CloudBlobContainer cloudBlobContainer;
SystemParameters systemParameters;
select systemParameters
where systemParameters. WIntegrationDataArea == curExt();
connectionString
= systemParameters. WDigitalSignConnectionString;
cloudStorageAccount
= CloudStorageAccount::Parse(connectionString);
cloudBlobClient
= cloudStorageAccount.CreateCloudBlobClient();
if(fileType == "FTInvoice" || fileType ==
"FTInvoiceAS")
{
cloudBlobContainer
= cloudBlobClient.GetContainerReference(systemParameters. WDigitalSignAzureContainerName);
// container name
cloudBlobDirectory = cloudBlobContainer.GetDirectoryReference("D365FTI");//File
path where the files are stored
}
else
if(fileType == "DebitNote" || fileType ==
"CreditNote" || fileType == "TaxInvoice")
{
cloudBlobContainer
= cloudBlobClient.GetContainerReference(systemParameters. WDigitalSignAzureContainerName);
// container name
cloudBlobDirectory = cloudBlobContainer.GetDirectoryReference("D365CNDN");//File
path where the files are stored
}
CloudBlockBlob blob
= cloudBlobDirectory.GetBlockBlobReference(fileName);
System.IO.Stream
stream = new System.IO.MemoryStream();
blob.DownloadToStream(stream,
null, null, null);
return
stream;
}
/// <summary>
/// To send email.
/// </summary>
/// <param name =
"stream1">File stream</param>
/// <param name =
"AccountId">CustAccount/param>
public
void sendEmail(System.IO.Stream stream1,str AccountId)
{
Filename fileName;
boolean ret;
if
(SysEmailParameters::find().SMTPUserName)
{
var
builder
= new SysMailerMessageBuilder();
fileName
= strFmt("%1_%2.zip", debitCreditVal,AccountId);
str messageBody,subject;
subject = strFmt("%1 for %2 in requested range
%3-%4",debitCreditVal,CustomerName,fromDateVal,toDateVal);
messageBody = strFmt("<p>Dear
Requestor</P><P>Please find attached %1 Request for requested range
%2-%3.<br>%4</p><p>Regards,<br>Wonder
Cement.</p>",debitCreditVal,fromDateVal,toDateVal,Note);
builder.setFrom(SysEmailParameters::find().SMTPUserName);
builder.addTo(strRTrim(strLTrim(Email)));
builder.setSubject(subject);
builder.setBody(messageBody);
if(stream1 != null)
{
builder.addAttachment(stream1, fileName);
}
ret
= SysMailerFactory::getNonInteractiveMailer().sendNonInteractive(builder.getMessage());
if (!ret)
{
warning ("@SYS80087");
}
if (ret)
{
responseMessage =
"Report genarated and sent to email successfully.";
}
}
}
}