AX 2009:需要在过帐发票之前打印形式发票

AX 2009: Need to print ProForma Invoice before the invoice has been posted

所以我的公司委托我创建一个批处理作业,为当天有装箱单 post 但没有发票的所有销售订单打印形式销售发票post还没有。他们要求这样做是因为他们希望在实际 posting 发票之前通过 PDF 文件查看发票。最有可能的是,他们可以 post 在一个流程中处理所有已批准的发票。

到目前为止,关于如何创建此批处理报告的所有示例 运行(我可以通过 Google 搜索找到)使用销售订单的 custInvoiceJour 条目来生成 SalesInvoice报告,但是,由于发票实际上尚未 posted,因此在这种情况下没有相应的 CustInvoiceJour 条目可使用

如果没有 posting (ProForma),我将如何创建 SalesInvoice,因为这些日记帐分录尚未创建?我知道这是可以做到的,因为您可以通过 UI.

这是我目前为批处理作业的 运行 方法编写的代码,当它 运行 时,它会出错,无法找到 custInvoiceJour 条目。

public void run()
{
// Arguments for function.
   Args args;
   ParmId parmId;
   ReportRun reportRun;
   SalesTable salesTable;
   PrintJobSettings printJobSettings;
   SalesFormLetter formLetter;

   select salesTable where salesTable.DocumentStatus == DocumentStatus::PackingSlip && salesTable.SalesStatus == SalesStatus::Delivered;

   printJobSettings = new PrintJobSettings();
   printJobSettings.setTarget(PrintMedium::File);
   printJobSettings.format(PrintFormat::PDF);
   printJobSettings.fileName("C:\temp\proforma_invoice.pdf");

   formLetter = SalesFormLetter::construct(DocumentStatus::Invoice);

   formLetter.proforma(true);
   formLetter.printFormLetter(true);
   formLetter.updatePrinterSettingsFormLetter(printJobSettings.packPrintJobSettings());

   args = new Args(ReportStr(SalesInvoice));
   args.caller(formLetter);
   args.parmEnum(PrintCopyOriginal::Original);
   args.parmEnumType(enumnum(PrintCopyOriginal));
   args.record(salesTable);

   reportRun = new ReportRun(args);
   reportRun.printJobSettings().setTarget(PrintMedium::File);
   reportRun.printJobSettings().format(PrintFormat::PDF);
   reportRun.printJobSettings().fileName("C:\temp\proforma_invoice.pdf");
   reportRun.prompt();
   reportRun.run();

}

您可以使用下面的代码将形式保存到文件

public void run()
{
    SalesTable          salesTable;
    PrintJobSettings    printJobSettings;
    SalesFormLetter     salesFormLetter;
    ;

    select firstOnly salesTable
        where salesTable.DocumentStatus == DocumentStatus::PackingSlip
           && salesTable.SalesStatus    == SalesStatus::Delivered;

    printJobSettings = new PrintJobSettings();
    printJobSettings.setTarget(PrintMedium::File);
    printJobSettings.format(PrintFormat::PDF);
    printJobSettings.fileName(@'C:\Temp\proforma_invoice.pdf');

    salesFormLetter = SalesFormLetter::construct(DocumentStatus::Invoice);
    salesFormLetter.updatePrinterSettingsFormLetter(printJobSettings.packPrintJobSettings());
    salesFormLetter.update(salesTable, 
                           systemDateGet(), 
                           SalesUpdate::PackingSlip, 
                           AccountOrder::None, 
                           NoYes::Yes, 
                           NoYes::Yes);
}