From 39c7e15ef07d56c099620039a120daceb8c92714 Mon Sep 17 00:00:00 2001 From: Nigel Kukard Date: Sun, 14 Jul 2019 02:12:29 +0000 Subject: [PATCH] Fix up invoice title, number and document ID --- wiaflos/server/core/Invoicing.pm | 20 +++++++++++++++++--- wiaflos/server/core/templating.pm | 9 +++------ 2 files changed, 20 insertions(+), 9 deletions(-) diff --git a/wiaflos/server/core/Invoicing.pm b/wiaflos/server/core/Invoicing.pm index 66425ed..1d580af 100644 --- a/wiaflos/server/core/Invoicing.pm +++ b/wiaflos/server/core/Invoicing.pm @@ -1181,12 +1181,22 @@ sub sendInvoice # If no accounts address, use general address $billEmailAddr = @billEmailAddrs > 0 ? join(',',@billEmailAddrs) : join(',',@genEmailAddrs); + # Massage the data a bit + my $invoiceTitle; + my $invoiceNumber = $invoice->{'Number'}; + if ($proforma eq "yes") { + $invoiceTitle = "Proforma Invoice"; + $invoiceNumber =~ s/^INV/PRF/; + } else { + $invoiceTitle = "Tax Invoice Copy" + } + # Build array of stuff we can use my $vars = { 'WiaflosString' => $GENSTRING, # Document type - 'Title' => $proforma eq "yes" ? "PROFORMA INVOICE" : "TAX INVOICE COPY", + 'Title' => uc($invoiceTitle), # Client 'ClientName' => $client->{'Name'}, @@ -1197,7 +1207,7 @@ sub sendInvoice # Invoice 'ClientTaxReference' => defined($invoice->{'TaxReference'}) ? $invoice->{'TaxReference'} : "", - 'InvoiceNumber' => $invoice->{'Number'}, + 'InvoiceNumber' => $invoiceNumber, 'InvoiceOrderNumber' => defined($invoice->{'OrderNumber'}) ? $invoice->{'OrderNumber'} : "", 'InvoiceIssueDate' => $invoice->{'IssueDate'}, 'InvoiceDueDate' => $invoice->{'DueDate'}, @@ -1231,7 +1241,7 @@ sub sendInvoice my $tempDir = File::Temp->newdir(); # Invoice filename - my $invoiceFilename = sprintf('%s.%s', $invoice->{'Number'}, $format); + my $invoiceFilename = sprintf('%s.%s', $invoiceNumber, $format); $invoiceFilename =~ s,/,-,g; # Path of the invoice file we're generating my $invoicePath = sprintf('%s/%s',$tempDir,$invoiceFilename); @@ -1242,6 +1252,10 @@ sub sendInvoice # # Generate invoice # + # + # Work out the DOC_ID + my $documentID = sprintf('%s - %s - %s', $client->{'Name'}, $client->{'Code'}, $invoiceNumber); + $vars->{'DocumentID'} = $documentID; # Load template my $res = loadTemplate2($template,$vars,$invoicePath,$format); diff --git a/wiaflos/server/core/templating.pm b/wiaflos/server/core/templating.pm index 54a2874..3820b84 100644 --- a/wiaflos/server/core/templating.pm +++ b/wiaflos/server/core/templating.pm @@ -115,13 +115,13 @@ sub loadTemplate2 setError("Unsupported format '$format'"); return; } - + # Make sure this is for pdf... if (!$SUPPORTS_PDF) { setError("AWIT-Docplates couldn't be loaded"); return; } - + # Create our docplate object my $docplate = AWIT::Docplate->new(); # Loop with each of them @@ -147,11 +147,8 @@ sub loadTemplate2 $docplate->addPreProcessTemplate("bits/start.tt2"); $docplate->addPostProcessTemplate("bits/end.tt2"); - # Work out the DOC_ID - my $docid = sprintf('%s - Account %s - Invoice %s', $vars->{'ClientName'}, $vars->{'ClientCode'}, $vars->{'InvoiceNumber'}); - # Process template - if (!$docplate->process($templateName,{'DOC_ID' => $docid}, $texFile)) { + if (!$docplate->process($templateName,{'DOC_ID' => $vars->{'DocumentID'}}, $texFile)) { setError($docplate->error); return; } -- GitLab