Commit e1f1143c authored by Nigel Kukard's avatar Nigel Kukard
Browse files

* Added email address support to suppliers & clients

parent c1521394
......@@ -282,6 +282,13 @@ my $Suppliers_cmds = {
'help' => 'linkaddr supplier="<supplier ref>" type="<physical or postal>" address="<address>"',
'function' => \&ias::client::cmdline::Suppliers::linkAddress,
},
{
'command' => 'linkemail',
'regex' => 'linkemail',
'desc' => 'Link email address',
'help' => 'linkemail supplier="<supplier ref>" type="<accounts or general>" address="<address>"',
'function' => \&ias::client::cmdline::Suppliers::linkEmailAddress,
},
{
'command' => 'linkphnum',
'regex' => 'linkphnum',
......@@ -340,6 +347,13 @@ my $Clients_cmds = {
'help' => 'linkaddr client="<item id>" type="<physical or postal>" address="<address>"',
'function' => \&ias::client::cmdline::Clients::linkAddress,
},
{
'command' => 'linkemail',
'regex' => 'linkemail',
'desc' => 'Link email address',
'help' => 'linkemail client="<item id>" type="<accounts or general>" address="<address>"',
'function' => \&ias::client::cmdline::Clients::linkEmailAddress,
},
{
'command' => 'linkphnum',
'regex' => 'linkphnum',
......
......@@ -145,6 +145,48 @@ sub linkAddress
}
# Link email address
sub linkEmailAddress
{
my ($OUT,@args) = @_;
my $parms = parseArgs(@args);
if (!defined($parms->{'client'})) {
return -202;
}
if (!defined($parms->{'type'})) {
return -202;
}
if (!defined($parms->{'address'})) {
return -202;
}
my $detail;
$detail->{'ClientRef'} = $parms->{'client'};
$detail->{'Type'} = $parms->{'type'};
$detail->{'Address'} = $parms->{'address'};
my $res = soapCall($OUT,"Clients","linkEmailAddress",$detail);
if ($res == -2) {
print($OUT " => Database error\n");
return undef;
} elsif ($res == -3) {
print($OUT " => Parameter problem\n");
return undef;
} elsif ($res == -4) {
print($OUT " => Client not found\n");
return undef;
}
return $res;
}
# Link phone number
sub linkPhoneNumber
{
......@@ -213,6 +255,9 @@ sub show
my $phones = soapCall($OUT,"Clients","getPhoneNumbers",$detail);
return -1 if (ref $phones ne "ARRAY");
my $emailAddies = soapCall($OUT,"Clients","getEmailAddresses",$detail);
return -1 if (ref $phones ne "ARRAY");
print("
ID.....: ".$client->{'ID'}."
Ref....: ".$client->{'Ref'}."
......@@ -235,6 +280,13 @@ foreach my $item (@{$phones}) {
Phone Number: ".$item->{'Type'}."
".$item->{'PhNumber'}."
");
}
foreach my $item (@{$emailAddies}) {
print("
Email Address: ".$item->{'Type'}."
".$item->{'Address'}."
");
}
return 0;
......
......@@ -213,6 +213,9 @@ sub show
my $phones = soapCall($OUT,"Suppliers","getPhoneNumbers",$detail);
return -1 if (ref $phones ne "ARRAY");
my $emailAddies = soapCall($OUT,"Suppliers","getEmailAddresses",$detail);
return -1 if (ref $addies ne "ARRAY");
print("
ID.....: ".$supplier->{'ID'}."
Ref....: ".$supplier->{'Ref'}."
......@@ -235,6 +238,13 @@ foreach my $item (@{$phones}) {
Phone Number: ".$item->{'Type'}."
".$item->{'PhNumber'}."
");
}
foreach my $item (@{$emailAddies}) {
print("
Email Address: ".$item->{'Type'}."
".$item->{'Address'}."
");
}
return 0;
......
......@@ -516,6 +516,80 @@ sub linkPhoneNumber
}
# Link email address
# Parameters:
# ClientRef - Client ref
# Type - Address type, accounts or ?
# Address - Email address
sub linkEmailAddress
{
my ($detail) = @_;
# Verify client ref
if (!defined($detail->{'ClientRef'}) || $detail->{'ClientRef'} eq "") {
setError("No (or invalid) client ref provided");
return -3;
}
# Verify type
if (!defined($detail->{'Type'}) || $detail->{'Type'} eq "") {
setError("No email address type provided");
return -3;
}
# Verify address
if (!defined($detail->{'Address'}) || $detail->{'Address'} eq "") {
setError("No email address provided");
return -3;
}
# Decide on address type
my $typeID;
if ($detail->{'Type'} eq "accounts") {
$typeID = 1;
} elsif ($detail->{'Type'} eq "general") {
$typeID = 1;
} else {
setError("Invalid email address type provided");
return -3;
}
# Check if client exists
my $clientID;
if (($clientID = getClientIDFromRef($detail->{'ClientRef'})) < 1) {
return $clientID;
}
DBBegin();
# Link in client address
my $sth = DBDo("
INSERT INTO client_email
(ClientID,Type,Address)
VALUES
(
".DBQuote($clientID).",
".DBQuote($typeID).",
".DBQuote($detail->{'Address'})."
)
");
if (!$sth)
{
setError(ias::server::dblayer::Error());
DBRollback();
return -2;
}
# Grab last ID
my $ID = DBLastInsertID("client_email","ID");
DBCommit();
return $ID;
}
# Return an array of client addresses
# Parameters:
# ClientRef - Client ref
......@@ -579,6 +653,69 @@ sub getAddresses
}
# Return an array of client email addresses
# Parameters:
# ClientRef - Client ref
sub getEmailAddresses
{
my ($detail) = @_;
my @addresses = ();
# Verify client ref
if (!defined($detail->{'ClientRef'}) || $detail->{'ClientRef'} eq "") {
setError("No (or invalid) client ref provided");
return -3;
}
# Check if client exists
my $clientID;
if (($clientID = getClientIDFromRef($detail->{'ClientRef'})) < 1) {
return $clientID;
}
# Return list of addresses
my $sth = DBSelect("
SELECT
client_email.ID, client_email.ClientID, client_email.Type, client_email.Address
FROM
client_email
WHERE
client_email.ClientID = ".DBQuote($clientID)."
");
if (!$sth)
{
setError(ias::server::dblayer::Error());
return -2;
}
# Fetch rows
while (my $row = $sth->fetchrow_hashref()) {
my $item;
$item->{'ID'} = $row->{'ID'};
# Resolve type
if ($row->{'Type'} == 1) {
$item->{'Type'} = "accounts";
} elsif ($row->{'Type'} == 2) {
$item->{'Type'} = "general";
} else {
$item->{'Type'} = "unknown";
}
$item->{'Address'} = $row->{'Address'};
push(@addresses,$item);
}
DBFreeRes($sth);
return \@addresses;
}
# Return an array of client email phone numbers
# Parameters:
# ClientRef - Client ref
......
......@@ -415,6 +415,80 @@ sub linkAddress
}
# Link email address
# Parameters:
# SupplierRef - Supplier reference
# Type - Address type, accounts or ?
# Address - Address
sub linkEmailAddress
{
my ($detail) = @_;
# Verify supplier ref
if (!defined($detail->{'SupplierRef'}) || $detail->{'SupplierRef'} eq "") {
setError("No (or invalid) supplier ref provided");
return -3;
}
# Verify type
if (!defined($detail->{'Type'}) || $detail->{'Type'} eq "") {
setError("No email address type provided");
return -3;
}
# Verify address
if (!defined($detail->{'Address'}) || $detail->{'Address'} eq "") {
setError("No email address provided");
return -3;
}
# Decide on address type
my $typeID;
if ($detail->{'Type'} eq "accounts") {
$typeID = 1;
} elsif ($detail->{'Type'} eq "general") {
$typeID = 2;
} else {
setError("Invalid email address type provided");
return -3;
}
# Check if supplier exists
my $supplierID;
if (($supplierID = getSupplierIDFromRef($detail->{'SupplierRef'})) eq "") {
return $supplierID;
}
DBBegin();
# Link in supplier address
my $sth = DBDo("
INSERT INTO supplier_email
(SupplierID,Type,Address)
VALUES
(
".DBQuote($supplierID).",
".DBQuote($typeID).",
".DBQuote($detail->{'Address'})."
)
");
if (!$sth)
{
setError(ias::server::dblayer::Error());
DBRollback();
return -2;
}
# Grab last ID
my $ID = DBLastInsertID("supplier_email","ID");
DBCommit();
return $ID;
}
# Link PhNumber
# Parameters:
# SupplierRef - Supplier ref
......@@ -511,6 +585,8 @@ sub linkPhoneNumber
# Return an array of supplier addresses
# Parameters:
# SupplierRef - Supplier ref
sub getAddresses
{
my ($detail) = @_;
......@@ -571,6 +647,69 @@ sub getAddresses
}
# Return an array of supplier email addresses
# Parameters:
# SupplierRef - Supplier ref
sub getEmailAddresses
{
my ($detail) = @_;
my @addresses = ();
# Verify supplier ref
if (!defined($detail->{'SupplierRef'}) || $detail->{'SupplierRef'} eq "") {
setError("No (or invalid) supplier ref provided");
return -3;
}
# Check if supplier exists
my $supplierID;
if (($supplierID = getSupplierIDFromRef($detail->{'SupplierRef'})) < 1) {
return $supplierID;
}
# Return list of email addresses
my $sth = DBSelect("
SELECT
supplier_email.ID, supplier_email.SupplierID, supplier_email.Type, supplier_email.Address
FROM
supplier_email
WHERE
supplier_email.SupplierID = ".DBQuote($supplierID)."
");
if (!$sth)
{
setError(ias::server::dblayer::Error());
return -2;
}
# Fetch rows
while (my $row = $sth->fetchrow_hashref()) {
my $item;
$item->{'ID'} = $row->{'ID'};
# Resolve type
if ($row->{'Type'} == 1) {
$item->{'Type'} = "accounts";
} elsif ($row->{'Type'} == 2) {
$item->{'Type'} = "general";
} else {
$item->{'Type'} = "unknown";
}
$item->{'Address'} = $row->{'Address'};
push(@addresses,$item);
}
DBFreeRes($sth);
return \@addresses;
}
# Return an array of supplier email phone numbers
sub getPhoneNumbers
{
......
......@@ -188,6 +188,47 @@ sub linkAddress {
}
# Link email address
# Parameters:
# ClientRef - Client reference
# Type - Address type, accounts or general
# Address - Email address
sub linkEmailAddress {
my (undef,$data) = @_;
# Check if client is authorized to access this function
if (isAuthorized("linkEmailAddress") < 0) {
return -103;
}
# Check params
if (!defined($data->{'ClientRef'}) || $data->{'ClientRef'} eq "") {
return -101;
}
if (!defined($data->{'Type'}) || $data->{'Type'} eq "") {
return -101;
}
if (!defined($data->{'Address'}) || $data->{'Address'} eq "") {
return -101;
}
my $authInfo = getAuthData();
# Do transaction
my $detail;
$detail->{'ClientRef'} = $data->{'ClientRef'};
$detail->{'Type'} = $data->{'Type'};
$detail->{'Address'} = $data->{'Address'};
my $res = ias::server::Clients::linkEmailAddress($detail);
return $res;
}
# Link phone number
# Parameters:
# ClientRef - Client reference
......@@ -274,6 +315,48 @@ sub getAddresses {
}
# Return list of client email addresses
sub getEmailAddresses {
my (undef,$data) = @_;
# Check if client is authorized to access this function
if (isAuthorized("getEmailAddresses") < 0) {
return -103;
}
# Check params
if (!defined($data->{'ClientRef'}) || $data->{'ClientRef'} eq "") {
return -101;
}
my $authInfo = getAuthData();
my $detail;
$detail->{'ClientRef'} = $data->{'ClientRef'};
# Grab and sanitize data
my $rawData = ias::server::Clients::getEmailAddresses($detail);
if (ref $rawData ne "ARRAY") {
return -1;
}
# Build result
my @data;
foreach my $item (@{$rawData}) {
my $tmpItem;
$tmpItem->{'ID'} = $item->{'ID'};
$tmpItem->{'Type'} = $item->{'Type'};
$tmpItem->{'Address'} = $item->{'Address'};
push(@data,$tmpItem);
}
return \@data;
}
# Return list of client phone numbers
sub getPhoneNumbers {
my (undef,$data) = @_;
......
......@@ -188,6 +188,47 @@ sub linkAddress {
}
# Link email address
# Parameters:
# SupplierRef - Supplier reference
# Type - Address type, accounts or general
# Address - Email address
sub linkEmailAddress {
my (undef,$data) = @_;
# Check if client is authorized to access this function
if (isAuthorized("linkEmailAddress") < 0) {
return -103;
}
# Check params
if (!defined($data->{'SupplierRef'}) || $data->{'SupplierRef'} eq "") {
return -101;
}
if (!defined($data->{'Type'}) || $data->{'Type'} eq "") {
return -101;
}
if (!defined($data->{'Address'}) || $data->{'Address'} eq "") {
return -101;
}
my $authInfo = getAuthData();
# Do transaction
my $detail;
$detail->{'SupplierRef'} = $data->{'SupplierRef'};
$detail->{'Type'} = $data->{'Type'};
$detail->{'Address'} = $data->{'Address'};
my $res = ias::server::Suppliers::linkEmailAddress($detail);
return $res;
}
# Link phone number
# Parameters:
# SupplierRef - Supplier reference
......@@ -273,6 +314,47 @@ sub getAddresses {
}
# Return list of supplier email addresses
# Parameters:
# SupplierRef - Supplier reference
sub getEmailAddresses {
my (undef,$data) = @_;
# Check if client is authorized to access this function
if (isAuthorized("getEmailAddresses") < 0) {
return -103;
}
# Check params
if (!defined($data->{'SupplierRef'}) || $data->{'SupplierRef'} eq "") {
return -101;
}
my $authInfo = getAuthData();
# Grab and sanitize data
my $rawData = ias::server::Suppliers::getEmailAddresses($data);
if (ref $rawData ne "ARRAY") {
return -1;
}
# Build result
my @data;
foreach my $item (@{$rawData}) {
my $tmpItem;
$tmpItem->{'ID'} = $item->{'ID'};
$tmpItem->{'Type'} = $item->{'Type'};
$tmpItem->{'Address'} = $item->{'Address'};
push(@data,$tmpItem);
}
return \@data;
}