Commit 853f47ad authored by Nigel Kukard's avatar Nigel Kukard

Added additional invoice options format and proforma

parent b0a4daf8
# Invoicing functions
# Copyright (C) 2009-2014, AllWorldIT
# Copyright (C) 2009-2019, AllWorldIT
# Copyright (C) 2008, LinuxRulz
# Copyright (C) 2007 Nigel Kukard <nkukard@lbsd.net>
#
......@@ -77,7 +77,7 @@ our $pluginInfo = {
MenuItem => "Send",
Regex => "send",
Desc => "Send client invoice",
Help => 'send invoice="<invoice number>" sendto="<email[:addy1,addy2...] or file:filename>"',
Help => 'send invoice="<invoice number>" sendto="<email[:addy1,addy2...] or file:filename>" [proforma="yes"] [format="<html> or <pdf>"]',
Function => \&send,
},
{
......@@ -345,6 +345,8 @@ sub send
my $detail;
$detail->{'Number'} = $parms->{'invoice'};
$detail->{'SendTo'} = $parms->{'sendto'};
$detail->{'Format'} = $parms->{'format'};
$detail->{'Proforma'} = $parms->{'proforma'};
my $res = soapCall($OUT,"wiaflos/server/api/Invoicing","sendInvoice",$detail);
if ($res->{'Result'} != RES_OK) {
soapDebug($OUT,$res);
......
# SOAP interface to Invoicing module
# Copyright (C) 2009-2014, AllWorldIT
# Copyright (C) 2009-2019, AllWorldIT
# Copyright (C) 2008, LinuxRulz
# Copyright (C) 2007 Nigel Kukard <nkukard@lbsd.net>
#
......@@ -344,12 +344,22 @@ sub sendInvoice {
return SOAPResponse(RES_ERROR,ERR_S_PARAM,"Parameter 'SendTo' invalid");
}
if (defined($data->{'Proforma'}) && ($data->{'Proforma'} ne "yes" && $data->{'Proforma'} ne "no")) {
return SOAPResponse(RES_ERROR,ERR_S_PARAM,"Parameter 'Proforma' invalid");
}
if (defined($data->{'Format'}) && ($data->{'Format'} ne "html" && $data->{'Format'} ne "pdf")) {
return SOAPResponse(RES_ERROR,ERR_S_PARAM,"Parameter 'Format' invalid");
}
my $authInfo = wiaflos::server::api::auth::sessionGetData();
# Do transaction
my $detail;
$detail->{'Number'} = $data->{'Number'};
$detail->{'SendTo'} = $data->{'SendTo'};
$detail->{'Proforma'} = $data->{'Proforma'};
$detail->{'Format'} = $data->{'Format'};
my $res = wiaflos::server::core::Invoicing::sendInvoice($detail);
if ($res < 0) {
return SOAPResponse(RES_ERROR,$res,wiaflos::server::core::Invoicing::Error());
......
......@@ -1084,6 +1084,12 @@ sub sendInvoice
return ERR_PARAM;
}
# Default to PDF invoices
my $format = $detail->{'Format'} // "pdf";
# Default to not using proforma invoices
my $proforma = $detail->{'Proforma'} // "no";
# Pull in config
my $config = wiaflos::server::core::config::getConfig();
......@@ -1145,10 +1151,18 @@ sub sendInvoice
}
# If no billing address, use shipping address
$billAddr = defined($billAddr) ? $billAddr : $shipAddr;
$billAddr =~ s/\|/<br \/>/g;
# Setup shipping address from invoice
$shipAddr = $invoice->{'ShippingAddress'};
$shipAddr =~ s/\|/<br \/>/g;
# If we're using HTML, we need to add newlines
if ($format eq "html") {
$billAddr =~ s/\|/<br \/>/g;
$shipAddr =~ s/\|/<br \/>/g;
# If we're PDF, generate an arrayref instead
} elsif ($format eq "pdf") {
$billAddr = [ split(/\|/,$billAddr) ];
$shipAddr = [ split(/\|/,$shipAddr) ];
}
# Parse in email addresses
my $billEmailAddr;
......
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