Commit 0fe3eadb authored by Nigel Kukard's avatar Nigel Kukard
Browse files

* More major API changes

parent 1bfa5410
......@@ -164,7 +164,6 @@ sub createClient {
$detail->{'TaxReference'} = $data->{'TaxReference'};
$detail->{'CreateSubAccount'} = $data->{'CreateSubAccount'};
my $res = wiaflos::server::Clients::createClient($detail);
if ($res < 1) {
return SOAPResponse(RES_ERROR,$res,wiaflos::server::Clients::Error());
}
......
......@@ -22,6 +22,8 @@ use strict;
use warnings;
use Auth;
use wiaflos::constants;
use wiaflos::soap;
use wiaflos::server::Payments;
# Plugin info
......@@ -42,64 +44,67 @@ sub init {
Auth::aclAdd('Payments','createPayment','Payments/Add');
Auth::aclAdd('Payments','postPayment','Payments/Post');
# Allocations
Auth::aclAdd('Payments','getAllocations','Payments/Allocation/Show');
Auth::aclAdd('Payments','createAllocation','Payments/Allocation/Add');
Auth::aclAdd('Payments','getAllocations','Payments/Allocation/Show');
Auth::aclAdd('Payments','postAllocation','Payments/Allocation/Post');
Auth::aclAdd('Payments','getPaymentAllocations','Payments/Allocation/Show');
Auth::aclAdd('Payments','createPaymentAllocation','Payments/Allocation/Add');
Auth::aclAdd('Payments','getPaymentAllocations','Payments/Allocation/Show');
Auth::aclAdd('Payments','postPaymentAllocation','Payments/Allocation/Post');
}
# Create payment
# Parameters:
# SupplierRef - Supplier reference
# SupplierCode - Supplier code
# GLAccountCode - GL account where money was paid from
# PaymentRef - Reference for this payment
# Number - Reference for this payment
# Date - Date of payment
# Ref - GL account entry reference (bank statement reference for example)
# Reference - GL account entry reference (bank statement reference for example)
# Amount - Amount
sub createPayment {
my (undef,$data) = @_;
# Check params
if (!defined($data->{'SupplierRef'}) || $data->{'SupplierRef'} eq "") {
return -101;
if (!defined($data->{'SupplierCode'}) || $data->{'SupplierCode'} eq "") {
return SOAPResponse(RES_ERROR,ERR_S_PARAM,"Parameter 'SupplierCode' invalid");
}
if (!defined($data->{'GLAccountCode'}) || $data->{'GLAccountCode'} eq "") {
return -101;
return SOAPResponse(RES_ERROR,ERR_S_PARAM,"Parameter 'GLAccountCode' invalid");
}
if (!defined($data->{'PaymentRef'}) || $data->{'PaymentRef'} eq "") {
return -101;
if (!defined($data->{'Number'}) || $data->{'Number'} eq "") {
return SOAPResponse(RES_ERROR,ERR_S_PARAM,"Parameter 'Number' invalid");
}
if (!defined($data->{'Date'}) || $data->{'Date'} eq "") {
return -101;
return SOAPResponse(RES_ERROR,ERR_S_PARAM,"Parameter 'Date' invalid");
}
if (!defined($data->{'Ref'}) || $data->{'Ref'} eq "") {
return -101;
if (!defined($data->{'Reference'}) || $data->{'Reference'} eq "") {
return SOAPResponse(RES_ERROR,ERR_S_PARAM,"Parameter 'Reference' invalid");
}
if (!defined($data->{'Amount'}) || $data->{'Amount'} eq "") {
return -101;
return SOAPResponse(RES_ERROR,ERR_S_PARAM,"Parameter 'Amount' invalid");
}
my $authInfo = Auth::sessionGetData();
# Do transaction
my $detail;
$detail->{'SupplierRef'} = $data->{'SupplierRef'};
$detail->{'SupplierCode'} = $data->{'SupplierCode'};
$detail->{'GLAccountCode'} = $data->{'GLAccountCode'};
$detail->{'PaymentRef'} = $data->{'PaymentRef'};
$detail->{'Number'} = $data->{'Number'};
$detail->{'Date'} = $data->{'Date'};
$detail->{'Ref'} = $data->{'Ref'};
$detail->{'Reference'} = $data->{'Reference'};
$detail->{'Amount'} = $data->{'Amount'};
my $res = wiaflos::server::Payments::createPayment($detail);
if ($res < 1) {
return SOAPResponse(RES_ERROR,$res,wiaflos::server::Payments::Error());
}
return $res;
return SOAPResponse(RES_OK,$res);
}
......@@ -110,7 +115,7 @@ sub getPayments {
# Grab and sanitize data
my $rawData = wiaflos::server::Payments::getPayments();
if (ref $rawData ne "ARRAY") {
return -1;
return SOAPResponse(RES_ERROR,$rawData,wiaflos::server::Payments::Error());
}
# Build result
......@@ -121,24 +126,24 @@ sub getPayments {
$tmpItem->{'ID'} = $item->{'ID'};
$tmpItem->{'SupplierID'} = $item->{'SupplierID'};
$tmpItem->{'SupplierRef'} = $item->{'SupplierRef'};
$tmpItem->{'SupplierCode'} = $item->{'SupplierCode'};
$tmpItem->{'GLAccountID'} = $item->{'GLAccountID'};
$tmpItem->{'GLAccountCode'} = $item->{'GLAccountCode'};
$tmpItem->{'PaymentRef'} = $item->{'PaymentRef'};
$tmpItem->{'Number'} = $item->{'Number'};
$tmpItem->{'TransDate'} = $item->{'TransDate'};
$tmpItem->{'Ref'} = $item->{'Ref'};
$tmpItem->{'TransactionDate'} = $item->{'TransactionDate'};
$tmpItem->{'Reference'} = $item->{'Reference'};
$tmpItem->{'Amount'} = $item->{'Amount'};
$tmpItem->{'GLTransActID'} = $item->{'GLTransActID'};
$tmpItem->{'GLTransactionID'} = $item->{'GLTransactionID'};
$tmpItem->{'Posted'} = $item->{'Posted'};
push(@data,$tmpItem);
}
return \@data;
return SOAPResponse(RES_OK,\@data);
}
......@@ -151,11 +156,11 @@ sub getPayment {
# Grab and sanitize data
my $detail;
$detail->{'PaymentRef'} = $data->{'PaymentRef'};
$detail->{'Number'} = $data->{'Number'};
$detail->{'PaymentID'} = $data->{'PaymentID'};
my $rawData = wiaflos::server::Payments::getPayment($detail);
if (ref $rawData ne "HASH") {
return -1;
return SOAPResponse(RES_ERROR,$rawData,wiaflos::server::Payments::Error());
}
my $tmpItem;
......@@ -163,126 +168,137 @@ sub getPayment {
$tmpItem->{'ID'} = $rawData->{'ID'};
$tmpItem->{'SupplierID'} = $rawData->{'SupplierID'};
$tmpItem->{'SupplierRef'} = $rawData->{'SupplierRef'};
$tmpItem->{'SupplierCode'} = $rawData->{'SupplierCode'};
$tmpItem->{'GLAccountID'} = $rawData->{'GLAccountID'};
$tmpItem->{'GLAccountCode'} = $rawData->{'GLAccountCode'};
$tmpItem->{'PaymentRef'} = $rawData->{'PaymentRef'};
$tmpItem->{'Number'} = $rawData->{'Number'};
$tmpItem->{'TransDate'} = $rawData->{'TransDate'};
$tmpItem->{'Ref'} = $rawData->{'Ref'};
$tmpItem->{'TransactionDate'} = $rawData->{'TransactionDate'};
$tmpItem->{'Reference'} = $rawData->{'Reference'};
$tmpItem->{'Amount'} = $rawData->{'Amount'};
$tmpItem->{'GLTransActID'} = $rawData->{'GLTransActID'};
$tmpItem->{'GLTransactionID'} = $rawData->{'GLTransactionID'};
$tmpItem->{'Posted'} = $rawData->{'Posted'};
return $tmpItem;
return SOAPResponse(RES_OK,$tmpItem);
}
# Post payment
# Parameters:
# PaymentRef - Reference for this payment
# Number - Reference for this payment
sub postPayment
{
my (undef,$data) = @_;
# Check params
if (!defined($data->{'PaymentRef'}) || $data->{'PaymentRef'} eq "") {
return -101;
if (!defined($data->{'Number'}) || $data->{'Number'} eq "") {
return SOAPResponse(RES_ERROR,ERR_S_PARAM,"Parameter 'Number' invalid");
}
my $authInfo = Auth::sessionGetData();
# Do transaction
my $detail;
$detail->{'PaymentRef'} = $data->{'PaymentRef'};
$detail->{'Number'} = $data->{'Number'};
my $res = wiaflos::server::Payments::postPayment($detail);
if ($res < 1) {
return SOAPResponse(RES_ERROR,$res,wiaflos::server::Payments::Error());
}
return $res;
return SOAPResponse(RES_OK,$res);
}
# Post allocation
# Parameters:
# AllocationID - Allocation ID to post
sub postAllocation
# ID - Allocation ID to post
sub postPaymentAllocation
{
my (undef,$data) = @_;
# Check params
if (!defined($data->{'AllocationID'}) || $data->{'AllocationID'} eq "") {
return -101;
if (!defined($data->{'ID'}) || $data->{'ID'} eq "") {
return SOAPResponse(RES_ERROR,ERR_S_PARAM,"Parameter 'ID' invalid");
}
my $authInfo = Auth::sessionGetData();
# Do transaction
my $detail;
$detail->{'AllocationID'} = $data->{'AllocationID'};
my $res = wiaflos::server::Payments::postAllocation($detail);
$detail->{'ID'} = $data->{'ID'};
my $res = wiaflos::server::Payments::postPaymentAllocation($detail);
if ($res < 1) {
return SOAPResponse(RES_ERROR,$res,wiaflos::server::Payments::Error());
}
return $res;
return SOAPResponse(RES_OK,$res);
}
# Create allocation
# Parameters:
# PaymentRef - Reference for this payment
# SupplierInvoiceRef - Supplier invoice ref
# PaymentNumber - Payment number
# SupplierInvoiceNumber - Supplier invoice number
# Amount - Amount
sub createAllocation {
sub createPaymentAllocation {
my (undef,$data) = @_;
# Check params
if (!defined($data->{'PaymentRef'}) || $data->{'PaymentRef'} eq "") {
return -101;
if (!defined($data->{'PaymentNumber'}) || $data->{'PaymentNumber'} eq "") {
return SOAPResponse(RES_ERROR,ERR_S_PARAM,"Parameter 'Number' invalid");
}
if (!defined($data->{'SupplierInvoiceRef'}) || $data->{'SupplierInvoiceRef'} eq "") {
return -101;
if (!defined($data->{'SupplierInvoiceNumber'}) || $data->{'SupplierInvoiceNumber'} eq "") {
return SOAPResponse(RES_ERROR,ERR_S_PARAM,"Parameter 'SupplierInvoiceNumber' invalid");
}
if (!defined($data->{'Amount'}) || $data->{'Amount'} eq "") {
return -101;
return SOAPResponse(RES_ERROR,ERR_S_PARAM,"Parameter 'Amount' invalid");
}
my $authInfo = Auth::sessionGetData();
# Do transaction
my $detail;
$detail->{'PaymentRef'} = $data->{'PaymentRef'};
$detail->{'SupplierInvoiceRef'} = $data->{'SupplierInvoiceRef'};
$detail->{'PaymentNumber'} = $data->{'PaymentNumber'};
$detail->{'SupplierInvoiceNumber'} = $data->{'SupplierInvoiceNumber'};
$detail->{'Amount'} = $data->{'Amount'};
my $res = wiaflos::server::Payments::createAllocation($detail);
my $res = wiaflos::server::Payments::createPaymentAllocation($detail);
if ($res < 1) {
return SOAPResponse(RES_ERROR,$res,wiaflos::server::Payments::Error());
}
return $res;
return SOAPResponse(RES_OK,$res);
}
# Return list of payment allocations
sub getAllocations {
# Parameters:
# PaymentNumber - Number for this payment
sub getPaymentAllocations {
my (undef,$data) = @_;
# Check params
if (!defined($data->{'PaymentRef'}) || $data->{'PaymentRef'} eq "") {
return -101;
if (!defined($data->{'PaymentNumber'}) || $data->{'PaymentNumber'} eq "") {
return SOAPResponse(RES_ERROR,ERR_S_PARAM,"Parameter 'Number' invalid");
}
my $authInfo = Auth::sessionGetData();
# Grab and sanitize data
my $detail;
$detail->{'PaymentRef'} = $data->{'PaymentRef'};
my $rawData = wiaflos::server::Payments::getAllocations($detail);
$detail->{'Number'} = $data->{'PaymentNumber'};
my $rawData = wiaflos::server::Payments::getPaymentAllocations($detail);
if (ref $rawData ne "ARRAY") {
return -1;
return SOAPResponse(RES_ERROR,$rawData,wiaflos::server::Payments::Error());
}
# Build result
......@@ -292,20 +308,20 @@ sub getAllocations {
$tmpItem->{'ID'} = $item->{'ID'};
$tmpItem->{'PaymentRef'} = $item->{'PaymentRef'};
$tmpItem->{'Number'} = $item->{'Number'};
$tmpItem->{'SupplierInvoiceID'} = $item->{'SupplierInvoiceID'};
$tmpItem->{'SupplierInvoiceRef'} = $item->{'SupplierInvoiceRef'};
$tmpItem->{'SupplierInvoiceNumber'} = $item->{'SupplierInvoiceNumber'};
$tmpItem->{'Amount'} = $item->{'Amount'};
$tmpItem->{'GLTransActID'} = $item->{'GLTransActID'};
$tmpItem->{'GLTransactionID'} = $item->{'GLTransactionID'};
$tmpItem->{'Posted'} = $item->{'Posted'};
push(@data,$tmpItem);
}
return \@data;
return SOAPResponse(RES_OK,\@data);
}
......
......@@ -36,6 +36,7 @@ Tax
Suppliers
Invoicing
Purchasing
Payments
EOT
......@@ -158,7 +158,6 @@ sub create
$detail->{'TaxReference'} = $parms->{'taxref'};
$detail->{'CreateSubAccount'} = $parms->{'createsubaccount'};
my $res = soapCall($OUT,"Clients","createClient",$detail);
if ($res->{'Result'} != RES_OK) {
soapDebug($OUT,$res);
return $res->{'Result'};
......@@ -197,7 +196,6 @@ sub linkAddress
$detail->{'Type'} = $parms->{'type'};
$detail->{'Address'} = $parms->{'address'};
my $res = soapCall($OUT,"Clients","linkClientAddress",$detail);
if ($res->{'Result'} != RES_OK) {
soapDebug($OUT,$res);
return $res->{'Result'};
......@@ -236,7 +234,6 @@ sub linkEmailAddress
$detail->{'Type'} = $parms->{'type'};
$detail->{'Address'} = $parms->{'address'};
my $res = soapCall($OUT,"Clients","linkClientEmailAddress",$detail);
if ($res->{'Result'} != RES_OK) {
soapDebug($OUT,$res);
return $res->{'Result'};
......@@ -276,7 +273,6 @@ sub linkPhoneNumber
$detail->{'Number'} = $parms->{'number'};
$detail->{'Name'} = $parms->{'name'};
my $res = soapCall($OUT,"Clients","linkClientPhoneNumber",$detail);
if ($res->{'Result'} != RES_OK) {
soapDebug($OUT,$res);
return $res->{'Result'};
......@@ -382,9 +378,8 @@ sub remove
my $detail;
$detail->{'Code'} = $parms->{'client'};
my $res= soapCall($OUT,"Clients","removeClient",$detail);
if ($res->{'Result'} != RES_OK) {
soapDebug($res);
soapDebug($OUT,$res);
}
return $res->{'Result'};
......
......@@ -236,9 +236,7 @@ sub createTransaction
my $detail;
$detail->{'Date'} = $parms->{'date'};
$detail->{'Reference'} = $parms->{'reference'};
my $res = soapCall($OUT,"GL","createGLTransaction",$detail);
if ($res->{'Result'} == RES_OK) {
# Save this ID
$last{'transactionid'} = $res->{'Data'};
......@@ -269,9 +267,7 @@ sub postTransaction
my $detail;
$detail->{'ID'} = $parms->{'transaction'};
my $res = soapCall($OUT,"GL","postGLTransaction",$detail);
if ($res->{'Result'} == RES_OK) {
# Null the id
$last{'transactionid'} = undef;
......
......@@ -86,7 +86,7 @@ sub list
my $res = soapCall($OUT,"Inventory","getInventoryItem");
if (ref $res eq "ARRAY") {
if ($res->{'Result'} == RES_OK) {
print $OUT swrite(<<'END', "ID", "Ref", "Type", "Mode", "Description", "Income", "Asset", "Expense", "SellPrice");
+=======+===========+=========+========+==============================================+===============+==============+=============+===========+
| @|||| | @|||||||| | @|||||| | @||||| | @||||||||||||||||||||||||||||||||||||||||||| | @|||||||||||| | @||||||||||| | @|||||||||| | @|||||||| |
......@@ -101,10 +101,10 @@ END
+=======+===========+=========+========+==============================================+===============+==============+=============+===========+
END
} else {
return $res;
soapDebug($OUT,$res);
}
return 0;
return $res->{'Result'};
}
......@@ -158,7 +158,6 @@ sub create
$detail->{'Unit'} = $parms->{'unit'};
$detail->{'Discountable'} = $parms->{'discoutable'};
my $res = soapCall($OUT,"Inventory","createInventoryItem",$detail);
if ($res->{'Result'} != RES_OK) {
soapDebug($OUT,$res);
return $res->{'Result'};
......@@ -183,7 +182,6 @@ sub remove
my $detail;
$detail->{'Code'} = $parms->{'item'};
my $res = soapCall($OUT,"Inventory","removeInventoryItem",$detail);
if ($res->{'Result'} != RES_OK) {
soapDebug($OUT,$res);
}
......@@ -211,7 +209,6 @@ sub update
$detail->{'Unit'} = $parms->{'unit'};
$detail->{'Discountable'} = $parms->{'discoutable'};
my $res = soapCall($OUT,"Inventory","updateInventoryItem",$detail);
if ($res->{'Result'} != RES_OK) {
soapDebug($OUT,$res);
}
......
......@@ -235,7 +235,7 @@ sub show
$detail->{'Number'} = $parms->{'invoice'};
my $res = soapCall($OUT,"Invoicing","getInvoice",$detail);
if ($res->{'Result'} != RES_OK) {
soapDebug($res);
soapDebug($OUT,$res);
return $res->{'Result'};
}
......@@ -311,13 +311,16 @@ sub send
return ERR_C_PARAM;
}
my $detail;
$detail->{'Number'} = $parms->{'invoice'};
$detail->{'SendTo'} = $parms->{'sendto'};
my $res = soapCall($OUT,"Invoicing","sendInvoice",$detail);
if ($res->{'Result'} != RES_OK) {
soapDebug($OUT,$res);
return $res->{'Result'};
}
return $res;
return $res->{'Data'};
}
......
......@@ -51,7 +51,7 @@ our $pluginInfo = {
MenuItem => "CreatePayment",
Regex => "createpay(?:ment)? ",
Desc => "Create a payment",
Help => 'create supplier="<supplier ref>" glacc="<source of payment>" paymentref="<payment reference>" date="<payment date>" ref="<journal ref>" amount="<amount paid>"',
Help => 'create supplier="<supplier code>" account="<GL account source of payment>" number="<payment number>" date="<payment date>" reference="<journal reference>" amount="<amount paid>"',
Function => \&createPayment,
},
{
......@@ -65,28 +65,28 @@ our $pluginInfo = {
MenuItem => "Post",
Regex => "post ",
Desc => "Post payment",
Help => 'post payment="<payment reference>"',
Help => 'post payment="<payment number>"',
Function => \&postPayment,
},
{
MenuItem => "Allocate",
Regex => "alloc(?:ate)? ",
Desc => "Allocate monies from a payment",
Help => 'alloc payment="<payment reference>" invoice="<invoice>" amount="<amount to allocate>"',
Help => 'alloc payment="<payment number>" invoice="<supplier invoice number>" amount="<amount to allocate>"',
Function => \&createAllocation,
},
{
MenuItem => "PostAllocation",
Regex => "postalloc ",
Desc => "Post payment allocation",
Help => 'postalloc allocid="<allocation ID>>"',
Help => 'postalloc id="<allocation ID>>"',
Function => \&postAllocation,
},
{
MenuItem => "Show",
Regex => "show ",
Desc => "Show payment allocations",
Help => 'show payment="<payment reference>"',
Help => 'show payment="<payment number>"',
Function => \&show,
},
],
......@@ -111,46 +111,50 @@ sub createPayment
my $parms = parseArgs(@args);
if (!defined($parms->{'supplier'})) {
return -202;
print($OUT " => ERROR: Parameter 'supplier' not defined\n");
return ERR_C_PARAM;
}
if (!defined($parms->{'glacc'})) {
return -202;
if (!defined($parms->{'account'})) {
print($OUT " => ERROR: Parameter 'account' not defined\n");
return ERR_C_PARAM;
}
if (!defined($parms->{'paymentref'})) {
return -202;
if (!defined($parms->{'number'})) {
print($OUT " => ERROR: Parameter 'number' not defined\n");
return ERR_C_PARAM;
}
if (!defined($parms->{'date'})) {
return -202;
print($OUT " => ERROR: Parameter 'date' not defined\n");
return ERR_C_PARAM;
}
if (!defined($parms->{'ref'})) {
return -202;
print($OUT " => ERROR: Parameter 'reference' not defined\n");
return ERR_C_PARAM;
}
if (!defined($parms->{'amount'})) {
return -202;
print($OUT " => ERROR: Parameter 'amount' not defined\n");
return ERR_C_PARAM;
}
my $detail;
$detail->{'SupplierRef'} = $parms->{'supplier'};
$detail->{'GLAccRef'} = $parms->{'glacc'};
$detail->{'PaymentRef'} = $parms->{'paymentref'};
$detail->{'SupplierCode'} = $parms->{'supplier'};
$detail->{'GLAccount'} = $parms->{'account'};
$detail->{'PaymentNumber'} = $parms->{'number'};
$detail->{'Date'} = $parms->{'date'};
$detail->{'Ref'} = $parms->{'ref'};
$detail->{'Reference'} = $parms->{'reference'};
$detail->{'Amount'} = $parms->{'amount'};
my $res = soapCall($OUT,"Payments","createPayment",$detail);
if ($res == -2) {
print($OUT " => Database error\n");
} elsif ($res == -3) {
print($OUT " => Parameter problem\n");