Skip to content

PurchaseOrderService

Implements IPurchaseOrderService, batch-producing a PDF packet of pending (or specifically numbered) purchase orders and emailing it to the requested recipients while also saving a copy to a document store path. It depends on IUnitOfWork for reading purchase order, comment, and line-comment data, and IDocumentService (and its EmailService) to generate the PDF from an XML package definition and send the resulting email.

Purpose

  • Retrieves either all currently issue-pending, non-closed, non-canceled purchase orders, or a specific purchase order by number, along with their comments.
  • Maps purchase-order data to the printable contract, formatting vendor/ship-to addresses, dates, currency amounts, and reconstructing multi-part comment text from delimited comment fragments.
  • Renders the mapped purchase orders to a PDF via the document service, writes the PDF to the configured document store, and emails it to the configured recipients.
  • Parses semicolon-delimited email address lists and reassembles compound, delimited purchase-order comment text.

Context

  • Namespace: SAIF.Services.Corporate
  • Assembly/package: SAIF.Services (packaged inside the SAIF.SAIFCode.Core NuGet package)

Public members

Member Signature Purpose
PurchaseOrderService(...) public PurchaseOrderService(IUnitOfWork uow, IDocumentService documentService) Validates both collaborators are non-null via Enforce.ArgumentNotNull and wires them in.
ProduceAndEmailPurchaseOrderDocument public int ProduceAndEmailPurchaseOrderDocument(PurchaseOrderBatchParameters purchaseOrderBatchParameters) Validates the parameters are non-null, retrieves the matching purchase orders (all pending, or one by number), attaches their comments, maps them to the printable contract list, generates and emails the resulting PDF, and returns the count of purchase orders processed (returning 0 immediately if none match).
RetrieveComment public static string RetrieveComment(string compoundComment) Splits a comma-delimited compound comment string and reassembles everything from the fourth field onward (rejoined with commas) as the usable comment text, or returns an empty string if fewer than four fields are present.
ParseEmailAddresses public static IList<string> ParseEmailAddresses(string emails) Splits a semicolon-delimited string of email addresses into a list, or returns an empty list if the input is null/empty.

Behavioral notes

  • Purchase-order selection is exclusive: if PurchaseOrderBatchParameters.PurchaseOrderNumber is supplied, only orders whose ID contains that value are retrieved; otherwise all issue-pending, non-closed, non-canceled orders are retrieved.
  • Vendor and ship-to addresses, order/delivery dates, and monetary amounts are all formatted defensively (blank/placeholder date 1700-01-01 and negative/zero amounts render as empty strings) to avoid printing sentinel or invalid values on the PDF.
  • The generated PDF is both emailed (via _documentService.EmailService.SendEmail) and separately written to disk at _batchParameters.DocumentStore + filename, so a single call produces two persisted outputs.
  • RetrieveComment and ParseEmailAddresses are static utility methods usable independently of an instance, alongside the instance-based document generation workflow.

Sources

  • Services/SAIF.Services/Corporate/PurchaseOrderService.cs