Commit 42bdb59f authored by Nigel Kukard's avatar Nigel Kukard
Browse files

* Yet more major API & functionality changes

parent 70071389
......@@ -256,7 +256,7 @@ CREATE TABLE supplier_phnums (
Type TINYINT UNSIGNED NOT NULL, # 1 = phone, 2 = fax
Name VARCHAR(128) NOT NULL, # Descriptive name
PhNumber VARCHAR(128) NOT NULL,
Number VARCHAR(128) NOT NULL,
PRIMARY KEY (ID),
......
......@@ -26,6 +26,8 @@
package Auth;
use strict;
use warnings;
use wiaflos::version;
use wiaflos::server::dblayer; # Need this to seet db handle for this session
......
......@@ -20,6 +20,8 @@
package Cache;
use strict;
use warnings;
use wiaflos::version;
require Exporter;
......
......@@ -23,6 +23,7 @@ use warnings;
use Auth;
use wiaflos::constants;
use wiaflos::soap;
use wiaflos::server::Clients;
......@@ -39,7 +40,7 @@ sub init {
Auth::aclAdd('Clients','getClients','Clients/Show');
Auth::aclAdd('Clients','getClient','Clients/Show');
Auth::aclAdd('Clients','getClintAddresses','Clients/Show');
Auth::aclAdd('Clients','getClientAddresses','Clients/Show');
Auth::aclAdd('Clients','getClientPhoneNumbers','Clients/Show');
Auth::aclAdd('Clients','getClientEmailAddresses','Clients/Show');
......@@ -62,6 +63,11 @@ sub getClient {
my $authInfo = Auth::sessionGetData();
# Check params
if (!defined($data->{'ID'}) && !defined($data->{'Code'})) {
return SOAPResponse(RES_ERROR,ERR_S_PARAM,"Parameter 'ID' or 'Code' must be provided");
}
my $detail;
$detail->{'ID'} = $data->{'ID'};
$detail->{'Code'} = $data->{'Code'};
......@@ -69,7 +75,7 @@ sub getClient {
# Grab and sanitize data
my $rawData = wiaflos::server::Clients::getClient($detail);
if (ref $rawData ne "HASH") {
return $rawData;
return SOAPResponse(RES_ERROR,$rawData,wiaflos::server::Clients::Error());
}
# Build result
......@@ -80,12 +86,12 @@ sub getClient {
$tmpItem->{'Name'} = $rawData->{'Name'};
$tmpItem->{'RegNumber'} = $rawData->{'RegNumber'};
$tmpItem->{'TaxReference'} = $rawData->{'TaxReference'};
$tmpItem->{'GLAccID'} = $rawData->{'GLAccID'};
$tmpItem->{'GLAccNumber'} = $rawData->{'GLAccNumber'};
$tmpItem->{'GLAccountID'} = $rawData->{'GLAccountID'};
$tmpItem->{'GLAccountNumber'} = $rawData->{'GLAccountNumber'};
$tmpItem->{'ContactPerson'} = $rawData->{'ContactPerson'};
return $tmpItem;
return SOAPResponse(RES_OK,$tmpItem);
}
......@@ -95,9 +101,9 @@ sub getClients {
# Grab and sanitize data
my $rawData = wiaflos::server::Clients::getClients();;
my $rawData = wiaflos::server::Clients::getClients();
if (ref $rawData ne "ARRAY") {
return $rawData;
return SOAPResponse(RES_ERROR,$rawData,wiaflos::server::Clients::Error());
}
# Build result
......@@ -110,14 +116,14 @@ sub getClients {
$tmpItem->{'Name'} = $item->{'Name'};
$tmpItem->{'RegNumber'} = $item->{'RegNumber'};
$tmpItem->{'TaxReference'} = $item->{'TaxReference'};
$tmpItem->{'GLAccID'} = $item->{'GLAccID'};
$tmpItem->{'GLAccNumber'} = $item->{'GLAccNumber'};
$tmpItem->{'GLAccountID'} = $item->{'GLAccountID'};
$tmpItem->{'GLAccountNumber'} = $item->{'GLAccountNumber'};
$tmpItem->{'ContactPerson'} = $item->{'ContactPerson'};
push(@data,$tmpItem);
}
return \@data;
return SOAPResponse(RES_OK,\@data);
}
......@@ -135,15 +141,15 @@ sub createClient {
# Check params
if (!defined($data->{'Code'}) || $data->{'Code'} eq "") {
return ERR_S_PARAM;
return SOAPResponse(RES_ERROR,ERR_S_PARAM,"Parameter 'Code' invalid");
}
if (!defined($data->{'Name'}) || $data->{'Name'} eq "") {
return ERR_S_PARAM;
return SOAPResponse(RES_ERROR,ERR_S_PARAM,"Parameter 'Name' invalid");
}
if (!defined($data->{'GLAccountNumber'}) || $data->{'GLAccountNumber'} eq "") {
return ERR_S_PARAM;
return SOAPResponse(RES_ERROR,ERR_S_PARAM,"Parameter 'GLAccountNumber' invalid");
}
......@@ -159,7 +165,11 @@ sub createClient {
$detail->{'CreateSubAccount'} = $data->{'CreateSubAccount'};
my $res = wiaflos::server::Clients::createClient($detail);
return $res;
if ($res < 1) {
return SOAPResponse(RES_ERROR,$res,wiaflos::server::Clients::Error());
}
return SOAPResponse(RES_OK,$res);
}
......@@ -174,15 +184,15 @@ sub linkClientAddress {
# Check params
if (!defined($data->{'Code'}) || $data->{'Code'} eq "") {
return ERR_S_PARAM;
return SOAPResponse(RES_ERROR,ERR_S_PARAM,"Parameter 'Code' invalid");
}
if (!defined($data->{'Type'}) || $data->{'Type'} eq "") {
return ERR_S_PARAM;
return SOAPResponse(RES_ERROR,ERR_S_PARAM,"Parameter 'Type' invalid");
}
if (!defined($data->{'Address'}) || $data->{'Address'} eq "") {
return ERR_S_PARAM;
return SOAPResponse(RES_ERROR,ERR_S_PARAM,"Parameter 'Address' invalid");
}
......@@ -195,7 +205,11 @@ sub linkClientAddress {
$detail->{'Address'} = $data->{'Address'};
my $res = wiaflos::server::Clients::linkClientAddress($detail);
return $res;
if ($res < 1) {
return SOAPResponse(RES_ERROR,$res,wiaflos::server::Clients::Error());
}
return SOAPResponse(RES_OK,$res);
}
......@@ -210,15 +224,15 @@ sub linkClientEmailAddress {
# Check params
if (!defined($data->{'Code'}) || $data->{'Code'} eq "") {
return ERR_S_PARAM;
return SOAPResponse(RES_ERROR,ERR_S_PARAM,"Parameter 'Code' invalid");
}
if (!defined($data->{'Type'}) || $data->{'Type'} eq "") {
return ERR_S_PARAM;
return SOAPResponse(RES_ERROR,ERR_S_PARAM,"Parameter 'Type' invalid");
}
if (!defined($data->{'Address'}) || $data->{'Address'} eq "") {
return ERR_S_PARAM;
return SOAPResponse(RES_ERROR,ERR_S_PARAM,"Parameter 'Address' invalid");
}
......@@ -231,7 +245,11 @@ sub linkClientEmailAddress {
$detail->{'Address'} = $data->{'Address'};
my $res = wiaflos::server::Clients::linkClientEmailAddress($detail);
return $res;
if ($res < 1) {
return SOAPResponse(RES_ERROR,$res,wiaflos::server::Clients::Error());
}
return SOAPResponse(RES_OK,$res);
}
......@@ -248,15 +266,15 @@ sub linkClientPhoneNumber {
# Check params
if (!defined($data->{'Code'}) || $data->{'Code'} eq "") {
return ERR_S_PARAM;
return SOAPResponse(RES_ERROR,ERR_S_PARAM,"Parameter 'Code' invalid");
}
if (!defined($data->{'Type'}) || $data->{'Type'} eq "") {
return ERR_S_PARAM;
return SOAPResponse(RES_ERROR,ERR_S_PARAM,"Parameter 'Type' invalid");
}
if (!defined($data->{'Number'}) || $data->{'Number'} eq "") {
return ERR_S_PARAM;
return SOAPResponse(RES_ERROR,ERR_S_PARAM,"Parameter 'Number' invalid");
}
......@@ -270,7 +288,11 @@ sub linkClientPhoneNumber {
$detail->{'Name'} = $data->{'Name'};
my $res = wiaflos::server::Clients::linkClientPhoneNumber($detail);
return $res;
if ($res < 1) {
return SOAPResponse(RES_ERROR,$res,wiaflos::server::Clients::Error());
}
return SOAPResponse(RES_OK,$res);
}
......@@ -283,6 +305,11 @@ sub getClientAddresses {
my $authInfo = Auth::sessionGetData();
# Check params
if (!defined($data->{'ID'}) && !defined($data->{'Code'})) {
return SOAPResponse(RES_ERROR,ERR_S_PARAM,"Parameter 'ID' or 'Code' must be provided");
}
my $detail;
$detail->{'Code'} = $data->{'Code'};
$detail->{'ID'} = $data->{'ID'};
......@@ -290,7 +317,7 @@ sub getClientAddresses {
# Grab and sanitize data
my $rawData = wiaflos::server::Clients::getClientAddresses($detail);
if (ref $rawData ne "ARRAY") {
return $rawData;
return SOAPResponse(RES_ERROR,$rawData,wiaflos::server::Clients::Error());
}
# Build result
......@@ -305,7 +332,7 @@ sub getClientAddresses {
push(@data,$tmpItem);
}
return \@data;
return SOAPResponse(RES_OK,\@data);
}
......@@ -318,6 +345,11 @@ sub getClientEmailAddresses {
my $authInfo = Auth::sessionGetData();
# Check params
if (!defined($data->{'ID'}) && !defined($data->{'Code'})) {
return SOAPResponse(RES_ERROR,ERR_S_PARAM,"Parameter 'ID' or 'Code' must be provided");
}
my $detail;
$detail->{'Code'} = $data->{'Code'};
$detail->{'ID'} = $data->{'ID'};
......@@ -325,7 +357,7 @@ sub getClientEmailAddresses {
# Grab and sanitize data
my $rawData = wiaflos::server::Clients::getClientEmailAddresses($detail);
if (ref $rawData ne "ARRAY") {
return $rawData;
return SOAPResponse(RES_ERROR,$rawData,wiaflos::server::Clients::Error());
}
# Build result
......@@ -340,7 +372,7 @@ sub getClientEmailAddresses {
push(@data,$tmpItem);
}
return \@data;
return SOAPResponse(RES_OK,\@data);
}
......@@ -353,6 +385,11 @@ sub getClientPhoneNumbers {
my $authInfo = Auth::sessionGetData();
# Check params
if (!defined($data->{'ID'}) && !defined($data->{'Code'})) {
return SOAPResponse(RES_ERROR,ERR_S_PARAM,"Parameter 'ID' or 'Code' must be provided");
}
my $detail;
$detail->{'Code'} = $data->{'Code'};
$detail->{'ID'} = $data->{'ID'};
......@@ -360,7 +397,7 @@ sub getClientPhoneNumbers {
# Grab and sanitize data
my $rawData = wiaflos::server::Clients::getClientPhoneNumbers($detail);
if (ref $rawData ne "ARRAY") {
return $rawData;
return SOAPResponse(RES_ERROR,$rawData,wiaflos::server::Clients::Error());
}
# Build result
......@@ -375,7 +412,7 @@ sub getClientPhoneNumbers {
push(@data,$tmpItem);
}
return \@data;
return SOAPResponse(RES_OK,\@data);
}
......@@ -388,7 +425,7 @@ sub removeClient {
# Check params
if (!defined($data->{'Code'}) || $data->{'Code'} eq "") {
return ERR_S_PARAM;
return SOAPResponse(RES_ERROR,ERR_S_PARAM,"Parameter 'Address' invalid");
}
my $authInfo = Auth::sessionGetData();
......@@ -398,7 +435,7 @@ sub removeClient {
$detail->{'Code'} = $data->{'Code'};
my $res = wiaflos::server::Clients::removeClient($detail);
return $res;
return SOAPResponse(RES_OK,$res);
}
......
......@@ -22,6 +22,7 @@ use strict;
use warnings;
use Auth;
use wiaflos::soap;
use wiaflos::server::Engine;
# Plugin info
......
......@@ -23,6 +23,7 @@ use warnings;
use Auth;
use wiaflos::constants;
use wiaflos::soap;
use wiaflos::server::GL;
......@@ -50,7 +51,7 @@ sub init {
Auth::aclAdd('GL','createGLTransaction','GL/Transaction/Add');
Auth::aclAdd('GL','linkGLTransaction','GL/Transaction/Add');
Auth::aclAdd('GL','postTransaction','GL/Transaction/Post');
Auth::aclAdd('GL','postGLTransaction','GL/Transaction/Post');
Auth::aclAdd('GL','removeGLTransaction','GL/Transaction/Remove');
}
......@@ -66,7 +67,7 @@ sub getGLAccounts {
# Grab and sanitize data
my $rawData = wiaflos::server::GL::getGLAccounts();
if (ref $rawData ne "ARRAY") {
return $rawData;
return SOAPResponse(RES_ERROR,$rawData,wiaflos::server::GL::Error());
}
# Build result
......@@ -84,7 +85,7 @@ sub getGLAccounts {
push(@data,$tmpItem);
}
return \@data;
return SOAPResponse(RES_OK,\@data);
}
......@@ -96,7 +97,7 @@ sub getGLTransactions {
# Grab and sanitize data
my $rawData = wiaflos::server::GL::getGLTransactions();
if (ref $rawData ne "ARRAY") {
return $rawData;
return SOAPResponse(RES_ERROR,$rawData,wiaflos::server::GL::Error());
}
# Build result
......@@ -112,7 +113,7 @@ sub getGLTransactions {
push(@data,$tmpItem);
}
return \@data;
return SOAPResponse(RES_OK,\@data);
}
......@@ -126,11 +127,11 @@ sub createGLTransaction {
# Check params
if (!defined($data->{'Date'}) || $data->{'Date'} eq "") {
return ERR_S_PARAM;
return SOAPResponse(RES_ERROR,ERR_S_PARAM,"Parameter 'Date' invalid");
}
if (!defined($data->{'Reference'}) || $data->{'Reference'} eq "") {
return ERR_S_PARAM;
return SOAPResponse(RES_ERROR,ERR_S_PARAM,"Parameter 'Reference' invalid");
}
my $authInfo = Auth::sessionGetData();
......@@ -140,14 +141,18 @@ sub createGLTransaction {
$detail->{'Date'} = $data->{'Date'};
$detail->{'Reference'} = $data->{'Reference'};
my $res = wiaflos::server::GL::createGLTransaction($detail);
if ($res < 1) {
return SOAPResponse(RES_ERROR,$res,wiaflos::server::GL::Error());
}
return $res;
return SOAPResponse(RES_OK,$res);
}
# Link GL transaction
# Parameters:
# TransactionID - Transaction ID
# ID - Transaction ID
# AccountNumber - GL account number
# Amount - Amount to post
# Reference - Entry reference
......@@ -156,87 +161,99 @@ sub linkGLTransaction {
# Check params
if (!defined($data->{'TransactionID'}) || $data->{'TransactionID'} < 1) {
return ERR_S_PARAM;
if (!defined($data->{'ID'}) || $data->{'ID'} < 1) {
return SOAPResponse(RES_ERROR,ERR_S_PARAM,"Parameter 'ID' invalid");
}
if (!defined($data->{'AccountNumber'}) || $data->{'AccountNumber'} eq "") {
return ERR_S_PARAM;
return SOAPResponse(RES_ERROR,ERR_S_PARAM,"Parameter 'AccountNumber' invalid");
}
if (!defined($data->{'Amount'})) {
return ERR_S_PARAM;
return SOAPResponse(RES_ERROR,ERR_S_PARAM,"Parameter 'Amount' invalid");
}
my $authInfo = Auth::sessionGetData();
# Do transaction
my $detail;
$detail->{'TransactionID'} = $data->{'TransactionID'};
$detail->{'ID'} = $data->{'ID'};
$detail->{'AccountNumber'} = $data->{'AccountNumber'};
$detail->{'Amount'} = $data->{'Amount'};
$detail->{'Reference'} = $data->{'Reference'};
my $res = wiaflos::server::GL::linkGLTransactionByAccountNumber($detail);
if ($res < 1) {
return SOAPResponse(RES_ERROR,$res,wiaflos::server::GL::Error());
}
return $res;
return SOAPResponse(RES_OK,$res);
}
# Post GL transaction
# Parameters:
# TransactionID - Transaction ID
# ID - Transaction ID
sub postGLTransaction {
my (undef,$data) = @_;
# Check params
if (!defined($data->{'TransactionID'}) || $data->{'TransactionID'} < 1) {
return ERR_S_PARAM;
if (!defined($data->{'ID'}) || $data->{'ID'} < 1) {
return SOAPResponse(RES_ERROR,ERR_S_PARAM,"Parameter 'ID' invalid");
}
my $authInfo = Auth::sessionGetData();
# Do transaction
my $detail;
$detail->{'TransactionID'} = $data->{'TransactionID'};
my $res = wiaflos::server::GL::postGLTansaction($detail);
$detail->{'ID'} = $data->{'ID'};
my $res = wiaflos::server::GL::postGLTransaction($detail);
if ($res < 0) {
return SOAPResponse(RES_ERROR,$res,wiaflos::server::GL::Error());
}
return $res;
return SOAPResponse(RES_OK,$res);
}
# Remove GL transaction
# Parameters:
# TransactionID - Transaction ID
# ID - Transaction ID
sub removeGLTransaction {
my (undef,$data) = @_;
# Check params
if (!defined($data->{'TransactionID'}) || $data->{'TransactionID'} < 1) {
return ERR_S_PARAM;
if (!defined($data->{'ID'}) || $data->{'ID'} < 1) {
return SOAPResponse(RES_ERROR,ERR_S_PARAM,"Parameter 'ID' invalid");
}
my $authInfo = Auth::sessionGetData();
# Do transaction
my $detail;
$detail->{'TransactionID'} = $data->{'TransactionID'};
$detail->{'ID'} = $data->{'ID'};
my $res = wiaflos::server::GL::removeGLTransaction($detail);
return $res;
if ($res < 1) {
return SOAPResponse(RES_ERROR,$res,wiaflos::server::GL::Error());
}
return SOAPResponse(RES_OK,$res);
}
# Return list of GL transaction entries
# Parameters:
# TransactionID - Transaction ID
# ID - Transaction ID
sub getGLTransactionEntries {
my (undef,$data) = @_;
if (!defined($data->{'TransactionID'}) || $data->{'TransactionID'} < 1) {
return ERR_S_PARAM;
if (!defined($data->{'ID'}) || $data->{'ID'} < 1) {
return SOAPResponse(RES_ERROR,ERR_S_PARAM,"Parameter 'ID' invalid");
}
......@@ -244,10 +261,10 @@ sub getGLTransactionEntries {
# Grab and sanitize data
my $detail;
$detail->{'TransactionID'} = $data->{'TransactionID'};
$detail->{'ID'} = $data->{'ID'};
my $rawData = wiaflos::server::GL::getGLTransactionEntries($detail);
if (ref $rawData ne "ARRAY") {
return $rawData;
return SOAPResponse(RES_ERROR,$rawData,wiaflos::server::GL::Error());
}
# Build result
......@@ -257,16 +274,17 @@ sub getGLTransactionEntries {
$tmpItem->{'ID'} = $item->{'ID'};
$tmpItem->{'TransactionID'} = $item->{'TransactionID'};
$tmpItem->{'TransactionReference'} = $item->{'TransactionReference'};
$tmpItem->{'AccountID'} = $item->{'AccountID'};
$tmpItem->{'AccountName'} = $item->{'AccountName'};
$tmpItem->{'AccountNumber'} = $item->{'AccountReference'};
$tmpItem->{'AccountNumber'} = $item->{'AccountNumber'};
$tmpItem->{'Amount'} = $item->{'Amount'};
$tmpItem->{'Reference'} = $item->{'Reference'};
push(@data,$tmpItem);
}
return \@data;
return SOAPResponse(RES_OK,\@data);
}
......@@ -278,7 +296,7 @@ sub getGLAccountEntries {
if (!defined($data->{'AccountNumber'}) || $data->{'AccountNumber'} eq "") {
return ERR_S_PARAM;
return SOAPResponse(RES_ERROR,ERR_S_PARAM,"Parameter 'AccountNumber' invalid");
}
......@@ -289,7 +307,7 @@ sub getGLAccountEntries {
$detail->{'AccountNumber'} = $data->{'AccountNumber'};
my $rawData = wiaflos::server::GL::getGLAccountEntries($detail);
if (ref $rawData ne "ARRAY") {
return $rawData;
return SOAPResponse(RES_ERROR,$rawData,wiaflos::server::GL::Error());
}
# Build result
......@@ -298,7 +316,7 @@ sub getGLAccountEntries {
my $tmpItem;
$tmpItem->{'ID'} = $item->{'ID'};
$tmpItem->{'GLTransactionID'} = $item->{'GLTransactionID'};
$tmpItem->{'TransactionID'} = $item->{'TransactionID'};
$tmpItem->{'Reference'} = $item->{'Reference'};
$tmpItem->{'TransactionDate'} = $item->{'TransactionDate'};
$tmpItem->{'Amount'} = $item->{'Amount'};
......@@ -307,7 +325,7 @@ sub getGLAccountEntries {
push(@data,$tmpItem);
}
return \@data;
return SOAPResponse(RES_OK,\@data);
}
......@@ -324,19 +342,19 @@ sub createGLAccount {
if (!defined($data->{'Code'}) || $data->{'Code'} eq "") {
return ERR_S_PARAM;
return SOAPResponse(RES_ERROR,ERR_S_PARAM,"Parameter 'Code' invalid");
}