diff --git a/wiaflos/server/core/Invoicing.pm b/wiaflos/server/core/Invoicing.pm index 66425eddf399ed96c57d566db1ece3c650c16ad0..1d580af4652061c22f47dcc9a1054fbc093e9981 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 54a2874e93f59aac13e4f83984acd16edd77fcb2..3820b842261e75267c30e453204fefe4e417592c 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; }