Sunday, October 22, 2023

Generate Payment Advice report using x++

  Generate Payment Advice report using x++.




Way 1: 
            The system will download the PDF using the Print setting.

Way 2 :

        Get the stream to send the mail or store it in the server. For this, we have to add the parm method in the contract class and assign the value in savePrintArchiveDetails method.


Code:

    public void generatePaymAdvice(LedgerJournalTrans _ledgerJournalTrans)
    {
        Filename                        fileName;
        BankPaymAdviceVendControllerV2  controller  = new BankPaymAdviceVendControllerV2();
        BankPaymAdviceContract          contract;
        SRSPrintDestinationSettings     settings;
        
        fileName = strFmt("%1_%2_PaymemtAdvice.pdf", _ledgerjournalTrans.JournalNum, _ledgerjournalTrans.Voucher);

        contract = BankPaymAdviceContract::newFromPaymentLine(_ledgerjournalTrans, false);
        contract.parmLedgerJournalTransRecId(_ledgerJournalTrans.RecId);

        controller.parmArgs(new Args());
        controller.parmReportName(ssrsReportStr(BankPaymAdviceVendV2, Report));
        controller.parmShowDialog(false);
        controller.parmLoadFromSysLastValue(false);
        controller.parmReportContract().parmRdpContract(contract);
        
        // Way 1
        settings = controller.parmReportContract().parmPrintSettings();
        settings.printMediumType(SRSPrintMediumType::Archive);
        settings.fileName(fileName);
        settings.fileFormat(SRSReportFileFormat::PDF);
        settings.overwriteFile(true);

        controller.startOperation();
    }

Way 2:
Contract class code:

    [ExtensionOf(classStr(SRSPrintArchiveContract))]
    public final class SRSPrintArchiveContract_Extension
    {
	public RefRecId printJobHeaderRecId;

	public RefRecId parmPrintJobHeaderRecId(RefRecId _printJobHeaderRecId = printJobHeaderRecId)
	{
	    printJobHeaderRecId = _printJobHeaderRecId;

    	    return printJobHeaderRecId;
	}

	public RecId savePrintArchiveDetails(container binData)
	{
	    RecId recId = next savePrintArchiveDetails(binData);

	    this.parmPrintJobHeaderRecId(recId);

	    return recId;
	}
    }


Call the below code after controller.Startoperation();

    

    DocuRef  		docuref;
    PrintJobHeader 	printJobHeader;
    select forupdate printJobHeader
        where printJobHeader.RecId == settings.parmSRSPrintArchiveContract().parmPrintJobHeaderRecId();
        
   select forupdate docuref
        where docuref.RefRecId == printJobHeader.RecId
           && docuRef.ActualCompanyId == curExt(); 	



			
   BinData 	        binData 	= new BinData();
   System.IO.Stream 	fileStream 	= DocumentManagement::getAttachmentStream(docuRef);

   File::SendFileToUser(fileStream, fileName);
		
   ttsbegin;
   printJobHeader.delete();
   docuref.delete();
   ttscommit;
    


Get the 'Stream' from docuref table:

 	DocuRef                         docuRef;
	DocuType                        DocuType;
	DocuValue                       docuValue;

	select * from docuRef
	    order by docuRef.createddatetime desc
	    exists join docuValue
		where docuValue.RecId == docuRef.ValueRecId
		    && docuValue.FileType =="PDF"
		    && docuRef.RefTableId == PurchTable.TableId
		    && docuRef.RefRecId      == PurchTable.RecId
		    && docuRef.RefCompanyId  == PurchTable.DataAreaId;
     System.IO.Stream 	fileStream  = DocumentManagement::getAttachmentStream(docuRef);

     File::SendFileToUser(fileStream, fileName);
    // Convert Stream into memory stream

     var memoryStream = new System.IO.MemoryStream();
     fileStream.CopyTo(memoryStream);

        


Keep Daxing!!


No comments:

Post a Comment