Monday, October 17, 2016

Sending PO report to email

/// <summary>
/// this method has logic to send email
/// </summary>
/// <param name="_vendTable">
/// getting vendor table as parameter
/// </param>
/// <param name="_purchTable">
/// getting purchase order table as parameter
/// </param>
/// <param name="_emailAttachments">
/// getting whether the email checkbox is selected or not as parameter
/// </param>
// Begin
public static void sendEmailSysMailer(VendTable _vendTable, PurchTable _purchTable, NoYes _emailAttachments=NoYes::No)
{
    InteropPermission permission = new InteropPermission(InteropKind::ComInterop);
    SysMailer   sysMailer;
    str         filePathName, reportFilePathName;
    VendTable   vendTable=_vendTable;
    DocuRef     docuRef;
    EmailBase   sender;
    Notes       body;
    ;

    if(_purchTable.RecId)
    {
        sender = SysUserInfo::find(curUserId()).Email;

        permission.assert();
        sysMailer = new SysMailer();

        //reportFilePathName = PurchParameters::find().AvaPurchOrderPath + '\\default.pdf';
        reportFilePathName = PurchParameters::find().AvaPurchOrderPath + '\\' + _purchTable.PurchId +'.pdf';
        // AVAEmailPOConfirmationWithAttachments - Hema - 28/Aug/2016 - Begin
        //Requirement change
        //Attach PO report as external attachment to the PO header and then send it to vendor's email
        AvaSendingEmailPOConfirmation::attachPOReport(_purchTable, reportFilePathName);
        //sysMailer.attachments().add(reportFilePathName);
        // AVAEmailPOConfirmationWithAttachments - Hema - 28/Aug/2016 - End

        if(_emailAttachments == NoYes::Yes)
        {
            //info('Sender email id: ' + sender);
            while select docuRef
                where docuRef.RefRecId    == _purchTable.RecId
                   && docuRef.Restriction == DocuRestriction::External
                   && docuRef.RefTableId  == tableNum(PurchTable)
                {
                    filePathName = docuRef.completeFilename();
                    if( !((docuRef.docuType().TypeGroup == DocuTypeGroup::Note) || (docuRef.docuType().TypeGroup == DocuTypeGroup::URL)))
                    {
                        sysMailer.attachments().add(filePathName);
                    }
                }
            //info('Vendor primary email id: ' +vendTable.email());
            body = 'Please see attached '+ _purchTable.PurchId +' from Golden Spread Electric Cooperative.  Feel free to contact us if you have any questions and concerns.';
            //sysMailer.quickSend("bijan.ghofranian@avanade.com",vendTable.email(),'PO Confirmed '+_purchTable.PurchId,'Your PO '+ _purchTable.PurchId + ' was Confirmed');
            sysMailer.quickSend(sender,vendTable.email(),'PO Confirmed '+_purchTable.PurchId,body);
            info(strFmt("@AVA39",vendTable.email())); //Email sent to %1
            sysMailer.attachments().clear();
        }
        CodeAccessPermission::revertAssert();
    }
}
//End

No comments:

Post a Comment