I queried the dbo.DocReport table to make sure I passed the correct context (Order.CDFs) for the "Disbursements Summary (Legal) - CDF" report.
The document was generated and successfully written to a PDF; however, it did not contain any data from the order.
Something similar happened when I tried to generate a Transaction Form for one of the receipts.
I checked the table and passed in the corresponding context (Ledger.Transaction) for the "Transaction Form (Pulte - 1 copy)" report and it was generated and written to a PDF.
This time one of the fields was populated (the receipt amount), but everything else was blank.
Lastly, I tried generating a Transaction Form again, instead using the "Transaction Form" template and it worked correctly.
The PDF was saved and all of the receipt data was filled in.
All of the report templates I mentioned are currently set up to be generated from the Reports button in the register, and all of them were successfully generated by SoftPro using the interface.
When trying to generate the docs programmatically, I tried two different orders (one CDF and one HUD) and adjusted the context and report name to match for each. The results were the same.
If required, I can email an export of the report templates to help reproduce the error.
Here is the code I used to test a CDF order:
Code: Select all
class Program
{
public static string DocPath = @"C:\Users\kwesterlage\Downloads\AutoGeneratedDocs\";
public const string WorkingTransactionForm = "Transaction Form";
public const string BrokenTransactionForm = "Transaction Form (Pulte - 1 copy)";
public const string BrokenDisbursementSummary = "Disbursements Summary (Legal) - CDF";
static void Main(string[] args)
{
try
{
string selectServerPath = ConfigurationManager.AppSettings["SelectServerPath"];
SelectServer select = new SelectServer(new Uri(selectServerPath));
string reason;
if (!select.TryAuthenticate(out reason))
{
// Write login failure reason to console and exit.
Console.WriteLine(reason);
return;
}
// Open Order
IOrderStore os = select.GetService<IOrderStore>();
IOrderInfo search = os.Orders.Where(x => x.Number == "TX-080421").FirstOrDefault();
if (search == null) return;
dynamic order = os.OpenOrder(search, true);
// Open Ledger for Transaction Form context
ILedgersManager lm = select.GetService<ILedgersManager>();
ILedgerInfo ledgerInfo = lm.GetLedgerForOrder(((IOrder)order).ToOrderInfo().Identifier.Guid);
IOrderLedger ledger = (IOrderLedger)lm.GetLedger(ledgerInfo);
// Setup for doc generation
IDocumentManager dm = select.GetService<IDocumentManager>();
IRendererFactory rendererFactory = select.GetService<IRendererFactory>();
IRenderer renderer = rendererFactory.Create();
var toGenerate = new List<string> { BrokenDisbursementSummary, BrokenTransactionForm, WorkingTransactionForm };
foreach (var doc in toGenerate)
{
var docInfos = dm.Documents.Where(x => x.Title == doc).FirstOrDefault();
if (docInfos != null)
{
switch (doc)
{
case WorkingTransactionForm:
case BrokenTransactionForm:
int i = 0;
string docPrefix = (doc == WorkingTransactionForm) ? "Working" : "Broken";
foreach (var transaction in ledger.Transactions.Where(t => t.Kind == TransactionKind.Receipt))
{
IRendering transactionDoc = renderer.Render(docInfos, transaction, null);
SaveRenderedDoc(transactionDoc, $"{DocPath}{docPrefix}TransactionForm_{i}.pdf");
i++;
}
break;
case BrokenDisbursementSummary:
IRendering disbursementDoc = renderer.Render(docInfos, order.CDFs, null);
SaveRenderedDoc(disbursementDoc, $"{DocPath}DisbursementSummary.pdf");
break;
default:
break;
}
}
}
}
catch (Exception ex)
{
Console.WriteLine(ex);
}
}
public static void SaveRenderedDoc(IRendering renderedDoc, string path)
{
using (Stream tmpFile = File.Create(path))
{
System.IO.Directory.CreateDirectory(DocPath);
Stream docStream = renderedDoc.Export(DocumentFormat.PortableDocumentFormat);
docStream.Seek(0, SeekOrigin.Begin);
docStream.CopyTo(tmpFile);
}
}
}