My customer, recently migrated from XERO to JIWA, says XERO had this fantastic function, they could click button on the sales order screen, and it would create PDF invoice.
Anybody tried this in JIWA, or is it even possible?
Ernst wrote:My customer, recently migrated from XERO to JIWA, says XERO had this fantastic function, they could click button on the sales order screen, and it would create PDF invoice.
Anybody tried this in JIWA, or is it even possible?
JiwaFinancials.Jiwa.JiwaApplication.Report.Configuration.Report reportRec = _.Manager.CollectionItemFactory.CreateCollectionItem<JiwaFinancials.Jiwa.JiwaApplication.Report.Configuration.Report>();
reportRec.ReadRecord(_invoice_report_rec_id);
JiwaFinancials.Jiwa.JiwaApplication.JiwaPrintReport.JiwaPrintReport jiwaPrintReport = _.Manager.BusinessLogicFactory.CreateBusinessLogic<JiwaFinancials.Jiwa.JiwaApplication.JiwaPrintReport.JiwaPrintReport>(null);
jiwaPrintReport.LoadReport(reportRec);
//update report parameters
IEnumerator en = jiwaPrintReport.JiwaReportRangeCollection.GetEnumerator();
while (en.MoveNext())
{
JiwaFinancials.Jiwa.JiwaApplication.JiwaPrintReport.JiwaReportRange range = (JiwaFinancials.Jiwa.JiwaApplication.JiwaPrintReport.JiwaReportRange)en.Current;
if (string.IsNullOrEmpty(range.FormulaKey) == false)
{
string parameterName = jiwaPrintReport.JiwaPrintFormulaCollection[range.FormulaKey].Name;
switch (parameterName)
{
case "Pass_CurrentHistNo":
range.Value = _HistoryNo_;
break;
case "Pass_SP_CurrentHistNo":
range.Value = _HistoryNo_;
break;
case "Pass_InvoiceNo":
range.Value = _InvoiceNo_;
break;
case "Pass_SP_InvoiceNo":
range.Value = _InvoiceNo_;
break;
case "Pass_InvoiceHistoryID":
range.Value = _InvoiceHistoryID_;
break;
case "Pass_SP_InvoiceHistoryID":
range.Value = _InvoiceHistoryID_;
break;
default:
break;
}
}
}
//export options, update report
string filename = _InvoiceNo_ + "-D" + _HistoryNo_.ToString("00") + "_" + DateTime.Now.ToString("yyyyMMdd]") + ".pdf";
string exportPath = Path.Combine(_exportFolder_, filename);
jiwaPrintReport.UpdateReport();
//export to disk using crystal report lib
jiwaPrintReport.CrystalReportObject.ExportToDisk(CrystalDecisions.Shared.ExportFormatType.PortableDocFormat, exportPath);
Option Explicit On
Option Infer On
Option Strict On
Imports JiwaFinancials.Jiwa
Imports JiwaFinancials.Jiwa.JiwaApplication
Imports JiwaFinancials.Jiwa.JiwaApplication.PrintGroup.SalesOrderReports
Imports JiwaFinancials.Jiwa.JiwaApplication.Security
Imports JiwaFinancials.Jiwa.JiwaDebtors
Imports JiwaFinancials.Jiwa.JiwaSales
Imports JiwaFinancials.Jiwa.JiwaSales.SalesOrder
Imports JiwaFinancials.Jiwa.JiwaSales.SalesQuote
Imports JiwaFinancials.Jiwa.JiwaSalesUI.SalesOrder
Imports System
Imports System.Diagnostics
Imports System.Linq
Namespace JiwaForums
Public Module SalesOrderMailer
''' <summary>
''' Format email for sending invoice or credit.
'''
''' NOTE: this is just a shell and would need to be modified to suit your customer.
''' </summary>
''' <param name="salesOrder"></param>
''' <returns></returns>
Private Function ParseEmailTemplate(ByVal salesOrder As SalesOrder) As FormattedEmailMessage
Dim result As New FormattedEmailMessage
result.AttachmentName = String.Format("{0}-D{1:00}", salesOrder.InvoiceNo, salesOrder.SelectedHistoryNo)
'
' Get Debtor details
'
Dim debtor As JiwaDebtors.Debtor = salesOrder.Manager.BusinessLogicFactory.CreateBusinessLogic(Of JiwaDebtors.Debtor)(Nothing)
debtor.Read(salesOrder.Debtor.DebtorID)
If salesOrder.CreditNote Then
' format credit note email
result.EmailSubject = String.Format("Credit note {0}.D{1:00} attached", salesOrder.InvoiceNo, salesOrder.CurrentHistoryNo)
result.EmailBody = ""
result.EmailFrom = ""
result.EmailTo = debtor.EmailAddress
result.EmailCC = ""
result.EmailBCC = ""
Else
' format invoice email
result.EmailSubject = String.Format("Invoice {0}.D{1:00} attached", salesOrder.InvoiceNo, salesOrder.CurrentHistoryNo)
result.EmailBody = ""
result.EmailFrom = ""
result.EmailTo = debtor.EmailAddress
result.EmailCC = ""
result.EmailBCC = ""
End If
Return result
End Function
''' <summary>
''' Emails an invoice or credit PDF
''' </summary>
''' <remarks>
''' Needs ParseEmailTemplate to do something useful with the template
''' </remarks>
''' <param name="salesOrder"></param>
''' <param name="documentType"></param>
''' <param name="docName"></param>
''' <param name="parentForm"></param>
Public Sub EmailSalesOrder(salesOrder As SalesOrder, documentType As SalesOrderReportCollection.SalesOrderPrintReportTypes, docName As String, parentForm As BaseSalesOrderEntryForm)
If salesOrder Is Nothing Then
Throw New ArgumentNullException(NameOf(salesOrder), $"{NameOf(salesOrder)} not supplied.")
End If
If parentForm Is Nothing Then
Throw New ArgumentNullException(NameOf(parentForm), $"{NameOf(parentForm)} not supplied.")
End If
If Debugger.IsAttached Then Debugger.Break()
If salesOrder.ChangeFlag Or salesOrder.InsertFlag Then
Throw New ApplicationException("Cannot email an invoice until the changes have been saved.")
End If
If salesOrder.Manager.Staff.GetAbstractPermission(salesOrder.ClientClassName, "Email") <> UserGroup.AccessLevels.Allow Then
Throw New ApplicationException("You do not have authority to email invoices.")
End If
If salesOrder.SalesOrderReports.Count = 0 Then
Throw New ApplicationException("No sales order reports have been defined.")
End If
Dim candidateReports = (
From r As SalesOrderReport In salesOrder.GetCandidateReportsToEmail().Cast(Of SalesOrderReport)
Where CInt(r.BillingType) = CInt(salesOrder.BillType) AndAlso
(r.DocumentType = documentType) AndAlso
(String.IsNullOrWhiteSpace(docName) OrElse String.Compare(docName, r.Name, True) = 0)
Order By r.ItemNo).ToList()
If Not candidateReports.Any Then
Throw New Exception("There are no reports that are applicable to this particular salesorder.")
End If
Dim formattedEmail = ParseEmailTemplate(salesOrder)
Try
Dim startParameters As New JiwaCollection(Of SalesOrderReport)
For Each r In candidateReports
startParameters.Add(r)
Next
Dim emailReportDialog As EmailReport = salesOrder.Manager.DialogFactory.CreateDialog(Of EmailReport)({startParameters}, parentForm, "Sales Order Entry")
emailReportDialog.EmailTo = formattedEmail.EmailTo
emailReportDialog.From = formattedEmail.EmailFrom
emailReportDialog.CC = formattedEmail.EmailCC
emailReportDialog.BCC = formattedEmail.EmailBCC
emailReportDialog.Subject = formattedEmail.EmailSubject
emailReportDialog.Message = formattedEmail.EmailBody
emailReportDialog.RequestReadReceipt = formattedEmail.RequestReadReceipt
emailReportDialog.NameToGiveAttachment = formattedEmail.AttachmentName
If emailReportDialog.ShowDialog(parentForm) <> System.Windows.Forms.DialogResult.OK Then
Return
End If
salesOrder.Email(emailReportDialog.SelectedReport,
emailReportDialog.NameToGiveAttachment,
emailReportDialog.From,
emailReportDialog.EmailTo,
emailReportDialog.RequestReadReceipt,
emailReportDialog.Subject,
emailReportDialog.CC,
emailReportDialog.BCC,
emailReportDialog.Message,
CrystalDecisions.Shared.ExportFormatType.PortableDocFormat)
Return
Catch ex As Exception
Throw
End Try
End Sub
End Module
Public Structure FormattedEmailMessage
Public Property EmailFrom As String
Public Property EmailTo As String
Public Property RequestReadReceipt As Boolean
Public Property EmailCC As String
Public Property EmailBCC As String
Public Property EmailSubject As String
Public Property EmailBody As String
Public Property AttachmentName As String
End Structure
End Namespace
pricerc wrote:Out of curiosity, why are they wanting to save a PDF of the invoice?
Xero do that because that's the only way you can actually print an invoice - you have to download a PDF and then print it.
I understand wanting to email a PDF with as few clicks as possible, but the saving of a PDF seems a bit superfluous as long as you have the database to pull up invoices.
Mike.Sheen wrote:If they want to just save it to file system, then it's not terribly difficult either, but I would question the value of that - I mean, they want to do something with that PDF - saving to file system first is probably just extra steps
Ernst wrote:also wanted a dangerous good document PDF uploaded via FTP to the carrier website, so the driver can view it while on route, and while carrying the load.
Return to Technical and or Programming
Users browsing this forum: No registered users and 21 guests