Commit 39c7e15e authored by Nigel Kukard's avatar Nigel Kukard

Fix up invoice title, number and document ID

parent 99ab5af5
......@@ -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);
......
......@@ -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;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment