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

* Added show supplier command

* Various bug fixes to SOAP engine
parent fa1663ea
......@@ -233,6 +233,13 @@ my $Suppliers_cmds = {
'help' => 'list',
'function' => \&ias::client::cmdline::Suppliers::list,
},
{
'command' => 'show',
'regex' => 'show',
'desc' => 'Show supplier',
'help' => 'show supplierid="<supplier id>"',
'function' => \&ias::client::cmdline::Suppliers::show,
},
# Invoicing
{
......
......@@ -188,6 +188,60 @@ sub linkPhoneNumber
}
# Show supplier
sub show
{
my ($OUT,@args) = @_;
my $parms = parseArgs(@args);
if (!defined($parms->{'supplierid'})) {
return -202;
}
my $detail;
$detail->{'SupplierID'} = $parms->{'supplierid'};
use Data::Dumper;
my $supplier = soapCall($OUT,"Suppliers","getSupplier",$detail);
#return -1 if ($supplier ne "HASH");
my $addies = soapCall($OUT,"Suppliers","getAddresses",$detail);
# return -1 if ($addies ne "ARRAY");
my $phones = soapCall($OUT,"Suppliers","getPhoneNumbers",$detail);
# return -1 if ($phones ne "ARRAY");
print("
ID.....:".$supplier->{'ID'}."
Ref....:".$supplier->{'Ref'}."
Name...:".$supplier->{'Name'}."
Reg....:".$supplier->{'RegNumber'}."
TaxRef.:".$supplier->{'TaxReference'}."
GLAcc..: ".$supplier->{'GLAcc'}."
");
foreach my $item (@{$addies}) {
print("
Address: ".$item->{'Type'}."
".$item->{'Address'}."
");
}
foreach my $item (@{$phones}) {
print("
Phone Number: ".$item->{'Type'}."
".$item->{'PhNumber'}."
");
}
return 0;
}
......
......@@ -90,6 +90,58 @@ sub supplierExists
# Return a hash containing the supplier
sub getSupplier
{
my ($detail) = @_;
# Verify supplier ID
if (!defined($detail->{'SupplierID'}) || $detail->{'SupplierID'} < 1) {
setError("No (or invalid) supplier ID provided");
return -3;
}
# Check if supplier exists
if ((my $res = supplierExists($detail->{'SupplierID'})) != 1) {
return $res;
}
# Return list of suppliers
my $sth = DBSelect("
SELECT
suppliers.ID, suppliers.Ref, suppliers.Name, suppliers.RegNumber, suppliers.TaxReference, suppliers.GLAccID, suppliers.ContactPerson
FROM
suppliers
WHERE
suppliers.ID = ".DBQuote($detail->{'SupplierID'})."
");
if (!$sth)
{
setError(ias::server::dblayer::Error());
return -2;
}
# Fetch rows
my $row = $sth->fetchrow_hashref();
my $item;
$item->{'ID'} = $row->{'ID'};
$item->{'Ref'} = $row->{'Ref'};
$item->{'Name'} = $row->{'Name'};
$item->{'RegNumber'} = $row->{'RegNumber'};
$item->{'TaxReference'} = $row->{'TaxReference'};
$item->{'GLAccID'} = $row->{'GLAccID'};
$item->{'GLAcc'} = ias::server::GL::getAccRef($row->{'GLAccID'});
$item->{'ContactPerson'} = $row->{'ContactPerson'};
DBFreeRes($sth);
return $item;
}
# Return an array of suppliers
sub getSuppliers
{
......@@ -401,6 +453,126 @@ sub linkPhoneNumber
}
# Return an array of supplier addresses
sub getAddresses
{
my ($detail) = @_;
my @addresses = ();
# Verify supplier ID
if (!defined($detail->{'SupplierID'}) || $detail->{'SupplierID'} < 1) {
setError("No (or invalid) supplier ID provided");
return -3;
}
# Check if supplier exists
if ((my $res = supplierExists($detail->{'SupplierID'})) != 1) {
return $res;
}
# Return list of addresses
my $sth = DBSelect("
SELECT
supplier_addrs.ID, supplier_addrs.SupplierID, supplier_addrs.Type, supplier_addrs.Address
FROM
supplier_addrs
WHERE
supplier_addrs.SupplierID = ".DBQuote($detail->{'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'} = "physical";
} elsif ($row->{'Type'} == 2) {
$item->{'Type'} = "postal";
} 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
{
my ($detail) = @_;
my @numbers = ();
# Verify supplier ID
if (!defined($detail->{'SupplierID'}) || $detail->{'SupplierID'} < 1) {
setError("No (or invalid) supplier ID provided");
return -3;
}
# Check if supplier exists
if ((my $res = supplierExists($detail->{'SupplierID'})) != 1) {
return $res;
}
# Return list of numbers
my $sth = DBSelect("
SELECT
supplier_phnums.ID, supplier_phnums.SupplierID, supplier_phnums.Type, supplier_phnums.PhNumber
FROM
supplier_phnums
WHERE
supplier_phnums.SupplierID = ".DBQuote($detail->{'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'} = "phone";
} elsif ($row->{'Type'} == 2) {
$item->{'Type'} = "fax";
} else {
$item->{'Type'} = "unknown";
}
$item->{'PhNumber'} = $row->{'PhNumber'};
push(@numbers,$item);
}
DBFreeRes($sth);
return \@numbers;
}
......
......@@ -32,8 +32,8 @@ sub getAccounts {
my $authInfo = getAuthData();
# Grab and sanitize data
my $rawData;
if (!($rawData = ias::server::GL::getAccounts())) {
my $rawData = ias::server::GL::getAccounts();
if (ref $rawData ne "ARRAY") {
return -1;
}
......@@ -66,9 +66,8 @@ sub getTransactions {
my $authInfo = getAuthData();
# Grab and sanitize data
my $rawData;
if (!($rawData = ias::server::GL::getTransactions())) {
print(STDERR 'ERROR: '.ias::server::GL::Error()."\n");
my $rawData = ias::server::GL::getTransactions();
if (ref $rawData ne "ARRAY") {
return -1;
}
......@@ -238,9 +237,8 @@ sub getTransactionEntries {
# Grab and sanitize data
my $detail;
$detail->{'GLTransActID'} = $data->{'GLTransActID'};
my $rawData;
if (!($rawData = ias::server::GL::getTransactionEntries($detail))) {
print(STDERR 'ERROR: '.ias::server::GL::Error()."\n");
my $rawData = ias::server::GL::getTransactionEntries($detail);
if (ref $rawData ne "ARRAY") {
return -1;
}
......@@ -285,9 +283,8 @@ sub getAccountEntries {
# Grab and sanitize data
my $detail;
$detail->{'GLAccID'} = $data->{'GLAccID'};
my $rawData;
if (!($rawData = ias::server::GL::getAccountEntries($detail))) {
print(STDERR 'ERROR: '.ias::server::GL::Error()."\n");
my $rawData = ias::server::GL::getAccountEntries($detail);
if (ref $rawData ne "ARRAY") {
return -1;
}
......
......@@ -32,8 +32,8 @@ sub getInventory {
my $authInfo = getAuthData();
# Grab and sanitize data
my $rawData;
if (!($rawData = ias::server::Inventory::getInventory())) {
my $rawData = ias::server::Inventory::getInventory();
if (ref $rawData ne "ARRAY") {
return -1;
}
......
......@@ -31,8 +31,8 @@ sub getInvoices {
my $authInfo = getAuthData();
# Grab and sanitize data
my $rawData;
if (!($rawData = ias::server::Purchasing::getInvoices())) {
my $rawData = ias::server::Purchasing::getInvoices();
if (ref $rawData ne "ARRAY") {
return -1;
}
......
......@@ -21,6 +21,49 @@ sub ping {
}
# Return a single supplier
sub getSupplier {
my (undef,$data) = @_;
# Check if client is authorized to access this function
if (isAuthorized("getSupplier") < 0) {
return -103;
}
# Check params
if (!defined($data->{'SupplierID'}) || $data->{'SupplierID'} eq "") {
return -101;
}
my $authInfo = getAuthData();
my $detail;
$detail->{'SupplierID'} = $data->{'SupplierID'};
# Grab and sanitize data
my $rawData = ias::server::Suppliers::getSupplier($detail);
if (ref $rawData ne "HASH") {
return -1;
}
# Build result
my $tmpItem;
$tmpItem->{'ID'} = $rawData->{'ID'};
$tmpItem->{'Ref'} = $rawData->{'Ref'};
$tmpItem->{'Name'} = $rawData->{'Name'};
$tmpItem->{'RegNumber'} = $rawData->{'RegNumber'};
$tmpItem->{'TaxReference'} = $rawData->{'TaxReference'};
$tmpItem->{'GLAccID'} = $rawData->{'GLAccID'};
$tmpItem->{'GLAcc'} = $rawData->{'GLAcc'};
$tmpItem->{'ContactPerson'} = $rawData->{'ContactPerson'};
return $tmpItem;
}
# Return list of suppliers
sub getSuppliers {
# Check if client is authorized to access this function
......@@ -31,8 +74,8 @@ sub getSuppliers {
my $authInfo = getAuthData();
# Grab and sanitize data
my $rawData;
if (!($rawData = ias::server::Suppliers::getSuppliers())) {
my $rawData = ias::server::Suppliers::getSuppliers();;
if (ref $rawData ne "ARRAY") {
return -1;
}
......@@ -189,6 +232,84 @@ sub linkPhoneNumber {
}
# Return list of supplier addresses
sub getAddresses {
my (undef,$data) = @_;
# Check if client is authorized to access this function
if (isAuthorized("getAddresses") < 0) {
return -103;
}
# Check params
if (!defined($data->{'SupplierID'}) || $data->{'SupplierID'} < 0) {
return -101;
}
my $authInfo = getAuthData();
# Grab and sanitize data
my $rawData = ias::server::Suppliers::getAddresses($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;
}
# Return list of supplier phone numbers
sub getPhoneNumbers {
my (undef,$data) = @_;
# Check if client is authorized to access this function
if (isAuthorized("getPhoneNumbers") < 0) {
return -103;
}
# Check params
if (!defined($data->{'SupplierID'}) || $data->{'SupplierID'} < 0) {
return -101;
}
my $authInfo = getAuthData();
# Grab and sanitize data
my $rawData = ias::server::Suppliers::getPhoneNumbers($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->{'PhNumber'} = $item->{'PhNumber'};
push(@data,$tmpItem);
}
return \@data;
}
......
......@@ -148,10 +148,13 @@ sub authenticate {
allowAccess('Purchasing','getInvoices');
allowAccess('Suppliers','getSupplier');
allowAccess('Suppliers','getSuppliers');
allowAccess('Suppliers','createSupplier');
allowAccess('Suppliers','linkAddress');
allowAccess('Suppliers','linkPhoneNumber');
allowAccess('Suppliers','getAddresses');
allowAccess('Suppliers','getPhoneNumbers');
allowAccess('Session','getSessionKey');
......
Supports Markdown
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