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

* More major API changes

parent 42bdb59f
......@@ -30,3 +30,13 @@
* Check all modules and see if tax reference & note is being returned to info queries
* Only allow 2 suppliers to use same GL account if the user FORCES's the operation
ACCEPTED CHANGES
- Add language preference to Clients module
- Auditing fields for all tables, CreatedBy, CreatedDate, ModifiedBy, ModifiedDate. Dump row, store row, update row, dump row store row.
......@@ -291,7 +291,7 @@ CREATE TABLE supplier_invoices (
SupplierID BIGINT UNSIGNED NOT NULL,
# Our reference
InvoiceNumber VARCHAR(32) NOT NULL,
Number VARCHAR(32) NOT NULL,
# This is pulled in from supplier data
TaxReference VARCHAR(32), # Tax reference number, VAT/GST ... etc
......@@ -302,21 +302,21 @@ CREATE TABLE supplier_invoices (
DueDate DATE,
OrderNumber VARCHAR(64),
DiscTotal DECIMAL(10,2), # Add up all discount
DiscountTotal DECIMAL(10,2), # Add up all discount
SubTotal DECIMAL(10,2), # Add up all items sold
TaxTotal DECIMAL(10,2), # Add up tax of all items
InvTotal DECIMAL(10,2), # SubTotal + Tax total
Total DECIMAL(10,2), # SubTotal + Tax total
Note TEXT,
GLTransActID BIGINT UNSIGNED, # Not null if posted
GLTransactionID BIGINT UNSIGNED, # Not null if posted
Paid TINYINT NOT NULL DEFAULT '0', # Allocations can be referenced with SupplierInvoiceID
PRIMARY KEY (ID),
FOREIGN KEY (SupplierID) REFERENCES suppliers(ID),
FOREIGN KEY (GLTransActID) REFERENCES gl_transactions(ID)
FOREIGN KEY (GLTransactionID) REFERENCES gl_transactions(ID)
) ENGINE=InnoDB;
......@@ -366,19 +366,19 @@ CREATE TABLE payments (
SupplierID BIGINT UNSIGNED NOT NULL,
GLAccountID BIGINT UNSIGNED NOT NULL, # Sending account
PaymentNumber VARCHAR(128), # Payment number
Number VARCHAR(128), # Payment number
TransDate DATE NOT NULL,
TransactionDate DATE NOT NULL,
Reference VARCHAR(128), # Reference on account statement
Amount DECIMAL(10,2) NOT NULL,
GLTransActID BIGINT UNSIGNED, # Set if posted
GLTransactionID BIGINT UNSIGNED, # Set if posted
PRIMARY KEY (ID),
FOREIGN KEY (SupplierID) REFERENCES suppliers(ID),
FOREIGN KEY (GLAccountID) REFERENCES gl_accounts(ID),
FOREIGN KEY (GLTransActID) REFERENCES gl_transactions(ID)
FOREIGN KEY (GLTransactionID) REFERENCES gl_transactions(ID)
) ENGINE=InnoDB;
DROP TABLE IF EXISTS payment_alloc;
......@@ -412,7 +412,7 @@ CREATE TABLE supplier_creditnotes (
SupplierID BIGINT UNSIGNED NOT NULL,
# Our reference
CreditNoteNumber VARCHAR(32) NOT NULL,
Number VARCHAR(32) NOT NULL,
SupplierInvoiceID BIGINT UNSIGNED, # Link on our side to the invoice if its related to a specific one
# This is pulled in from supplier data
......@@ -424,17 +424,17 @@ CREATE TABLE supplier_creditnotes (
SubTotal DECIMAL(10,2), # Add up all items
TaxTotal DECIMAL(10,2), # Add up tax of all items
CNTotal DECIMAL(10,2), # SubTotal + Tax total
Total DECIMAL(10,2), # SubTotal + Tax total
Note TEXT,
GLTransActID BIGINT UNSIGNED, # Not null if posted
GLTransactionID BIGINT UNSIGNED, # Not null if posted
PRIMARY KEY (ID),
FOREIGN KEY (SupplierID) REFERENCES suppliers(ID),
FOREIGN KEY (SupplierInvoiceID) REFERENCES supplier_invoices(ID),
FOREIGN KEY (GLTransActID) REFERENCES gl_transactions(ID)
FOREIGN KEY (GLTransactionID) REFERENCES gl_transactions(ID)
) ENGINE=InnoDB;
......@@ -519,7 +519,7 @@ CREATE TABLE inventory_changes (
ID SERIAL,
InventoryID BIGINT UNSIGNED NOT NULL,
GLTransActID BIGINT UNSIGNED NOT NULL,
GLTransactionID BIGINT UNSIGNED NOT NULL,
QtyChange DECIMAL(12,4) NOT NULL,
SerialNumber VARCHAR(64), /* If we tracking stock, this will be the serial number */
......@@ -527,9 +527,9 @@ CREATE TABLE inventory_changes (
PRIMARY KEY (ID),
KEY (InventoryID,SerialNumber),
KEY (GLTransActID,InventoryID),
KEY (GLTransactionID,InventoryID),
FOREIGN KEY (InventoryID) REFERENCES inventory(ID),
FOREIGN KEY (GLTransActID) REFERENCES gl_transactions(ID)
FOREIGN KEY (GLTransactionID) REFERENCES gl_transactions(ID)
) ENGINE=InnoDB;
......@@ -574,7 +574,7 @@ CREATE TABLE invoices (
ClientID BIGINT UNSIGNED NOT NULL,
# Our reference
InvoiceNumber VARCHAR(32) NOT NULL,
Number VARCHAR(32) NOT NULL,
# This is pulled in from client data
ShippingAddress TEXT,
......@@ -585,21 +585,21 @@ CREATE TABLE invoices (
DueDate DATE,
OrderNumber VARCHAR(64),
DiscTotal DECIMAL(10,2), # Add up all items sold
DiscountTotal DECIMAL(10,2), # Add up all items sold
SubTotal DECIMAL(10,2), # Add up all items sold
TaxTotal DECIMAL(10,2), # Add up tax of all items
InvTotal DECIMAL(10,2), # SubTotal + Tax total
Total DECIMAL(10,2), # SubTotal + Tax total
Note TEXT,
GLTransActID BIGINT UNSIGNED, # Not null if posted
GLTransactionID BIGINT UNSIGNED, # Not null if posted
Paid TINYINT NOT NULL DEFAULT '0', # Allocations can be referenced with SupplierInvoiceID
PRIMARY KEY (ID),
FOREIGN KEY (ClientID) REFERENCES clients(ID),
FOREIGN KEY (GLTransActID) REFERENCES gl_transactions(ID)
FOREIGN KEY (GLTransactionId) REFERENCES gl_transactions(ID)
) ENGINE=InnoDB;
......@@ -647,19 +647,19 @@ CREATE TABLE receipts (
ClientID BIGINT UNSIGNED NOT NULL,
GLAccountID BIGINT UNSIGNED NOT NULL, # Sending account
ReceiptNumber VARCHAR(128), # Receipt number
Number VARCHAR(128), # Receipt number
TransDate DATE NOT NULL,
TransactionDate DATE NOT NULL,
Reference VARCHAR(128), # Reference on account statement
Amount DECIMAL(10,2) NOT NULL,
GLTransActID BIGINT UNSIGNED, # Set if posted
GLTransactionID BIGINT UNSIGNED, # Set if posted
PRIMARY KEY (ID),
FOREIGN KEY (ClientID) REFERENCES clients(ID),
FOREIGN KEY (GLAccountID) REFERENCES gl_accounts(ID),
FOREIGN KEY (GLTransActID) REFERENCES gl_transactions(ID)
FOREIGN KEY (GLTransactionID) REFERENCES gl_transactions(ID)
) ENGINE=InnoDB;
DROP TABLE IF EXISTS receipt_alloc;
......@@ -758,7 +758,7 @@ DROP TABLE IF EXISTS gl_transactions;
CREATE TABLE gl_transactions (
ID SERIAL,
TransDate DATE NOT NULL,
TransactionDate DATE NOT NULL,
Reference VARCHAR(128) NOT NULL,
......@@ -766,7 +766,7 @@ CREATE TABLE gl_transactions (
PRIMARY KEY (ID),
KEY (TransDate)
KEY (TransactionDate)
) ENGINE=InnoDB;
......@@ -775,7 +775,7 @@ DROP TABLE IF EXISTS gl_entries;
CREATE TABLE gl_entries (
ID SERIAL,
GLTransActID BIGINT UNSIGNED NOT NULL,
GLTransactionID BIGINT UNSIGNED NOT NULL,
Reference VARCHAR(128),
......@@ -784,7 +784,7 @@ CREATE TABLE gl_entries (
PRIMARY KEY (ID),
FOREIGN KEY (GLTransActID) REFERENCES gl_transactions(ID),
FOREIGN KEY (GLTransactionID) REFERENCES gl_transactions(ID),
FOREIGN KEY (GLAccountID) REFERENCES gl_accounts(ID)
) ENGINE=InnoDB;
......
......@@ -435,6 +435,10 @@ sub removeClient {
$detail->{'Code'} = $data->{'Code'};
my $res = wiaflos::server::Clients::removeClient($detail);
if ($res < 0) {
return SOAPResponse(RES_ERROR,$res,wiaflos::server::Clients::Error());
}
return SOAPResponse(RES_OK,$res);
}
......
......@@ -22,6 +22,8 @@ use strict;
use warnings;
use Auth;
use wiaflos::constants;
use wiaflos::soap;
use wiaflos::server::Invoicing;
......@@ -61,7 +63,7 @@ sub getInvoices {
$detail->{'Type'} = $data->{'Type'};
my $rawData = wiaflos::server::Invoicing::getInvoices($detail);
if (ref $rawData ne "ARRAY") {
return -1;
return SOAPResponse(RES_ERROR,$rawData,wiaflos::server::Invoicing::Error());
}
# Build result
......@@ -72,46 +74,46 @@ sub getInvoices {
$tmpItem->{'ID'} = $item->{'ID'};
$tmpItem->{'ClientID'} = $item->{'ClientID'};
$tmpItem->{'InvoiceRef'} = $item->{'InvoiceRef'};
$tmpItem->{'Number'} = $item->{'Number'};
$tmpItem->{'IssueDate'} = $item->{'IssueDate'};
$tmpItem->{'DueDate'} = $item->{'DueDate'};
$tmpItem->{'OrderNumber'} = $item->{'OrderNumber'};
$tmpItem->{'DiscTotal'} = $item->{'DiscTotal'};
$tmpItem->{'DiscountTotal'} = $item->{'DiscountTotal'};
$tmpItem->{'SubTotal'} = $item->{'SubTotal'};
$tmpItem->{'TaxTotal'} = $item->{'TaxTotal'};
$tmpItem->{'InvTotal'} = $item->{'InvTotal'};
$tmpItem->{'Total'} = $item->{'Total'};
$tmpItem->{'Paid'} = $item->{'Paid'};
push(@data,$tmpItem);
}
return \@data;
return SOAPResponse(RES_OK,\@data);
}
# Return client invoice
# Parameters:
# InvoiceRef - Client invoice number
# Number - Client invoice number
sub getInvoice {
my (undef,$data) = @_;
# Check params
if (!defined($data->{'InvoiceRef'}) || $data->{'InvoiceRef'} eq "") {
return -101;
if (!defined($data->{'Number'}) || $data->{'Number'} eq "") {
return SOAPResponse(RES_ERROR,ERR_S_PARAM,"Parameter 'Number' invalid");
}
my $authInfo = Auth::sessionGetData();
# Grab and sanitize data
my $detail;
$detail->{'InvoiceRef'} = $data->{'InvoiceRef'};
$detail->{'Number'} = $data->{'Number'};
my $rawData = wiaflos::server::Invoicing::getInvoice($detail);
if (ref $rawData ne "HASH") {
return -1;
return SOAPResponse(RES_ERROR,$rawData,wiaflos::server::Invoicing::Error());
}
# Build result
......@@ -120,7 +122,7 @@ sub getInvoice {
$tmpItem->{'ID'} = $rawData->{'ID'};
$tmpItem->{'ClientID'} = $rawData->{'ClientID'};
$tmpItem->{'InvoiceRef'} = $rawData->{'InvoiceRef'};
$tmpItem->{'Number'} = $rawData->{'Number'};
$tmpItem->{'ShippingAddress'} = $rawData->{'ShippingAddress'};
$tmpItem->{'TaxReference'} = $rawData->{'TaxReference'};
......@@ -129,37 +131,37 @@ sub getInvoice {
$tmpItem->{'DueDate'} = $rawData->{'DueDate'};
$tmpItem->{'OrderNumber'} = $rawData->{'OrderNumber'};
$tmpItem->{'DiscTotal'} = $rawData->{'DiscTotal'};
$tmpItem->{'DiscountTotal'} = $rawData->{'DiscountTotal'};
$tmpItem->{'SubTotal'} = $rawData->{'SubTotal'};
$tmpItem->{'TaxTotal'} = $rawData->{'TaxTotal'};
$tmpItem->{'InvTotal'} = $rawData->{'InvTotal'};
$tmpItem->{'Total'} = $rawData->{'Total'};
$tmpItem->{'Paid'} = $rawData->{'Paid'};
return $tmpItem;
return SOAPResponse(RES_OK,$tmpItem);
}
# Return list of items relating to an invoice
# Parameters:
# InvoiceRef - Client invoice number
# Number - Client invoice number
sub getInvoiceItems {
my (undef,$data) = @_;
# Check params
if (!defined($data->{'InvoiceRef'}) || $data->{'InvoiceRef'} eq "") {
return -101;
if (!defined($data->{'Number'}) || $data->{'Number'} eq "") {
return SOAPResponse(RES_ERROR,ERR_S_PARAM,"Parameter 'Number' invalid");
}
my $authInfo = Auth::sessionGetData();
# Grab and sanitize data
my $detail;
$detail->{'InvoiceRef'} = $data->{'InvoiceRef'};
$detail->{'Number'} = $data->{'Number'};
my $rawData = wiaflos::server::Invoicing::getInvoiceItems($detail);
if (ref $rawData ne "ARRAY") {
return -1;
return SOAPResponse(RES_ERROR,$rawData,wiaflos::server::Invoicing::Error());
}
# Build result
......@@ -168,9 +170,9 @@ sub getInvoiceItems {
my $tmpItem;
$tmpItem->{'ID'} = $item->{'ID'};
$tmpItem->{'Ref'} = $item->{'Ref'};
$tmpItem->{'SerialNumber'} = $item->{'SerialNumber'};
$tmpItem->{'InventoryID'} = $item->{'InventoryID'};
$tmpItem->{'InventoryRef'} = $item->{'InventoryRef'};
$tmpItem->{'InventoryCode'} = $item->{'InventoryCode'};
$tmpItem->{'Description'} = $item->{'Description'};
$tmpItem->{'Quantity'} = $item->{'Quantity'};
$tmpItem->{'Unit'} = $item->{'Unit'};
......@@ -185,14 +187,14 @@ sub getInvoiceItems {
push(@data,$tmpItem);
}
return \@data;
return SOAPResponse(RES_OK,\@data);
}
# Create client invoice
# Parameters:
# ClientRef - Client ref
# InvoiceRef - Invoice ref
# ClientCode - Client code
# Number - Invoice number
# IssueDate - Issue date
# DueDate - Due date
# Optional:
......@@ -204,28 +206,28 @@ sub createInvoice {
# Check params
if (!defined($data->{'ClientRef'}) || $data->{'ClientRef'} eq "") {
return -101;
if (!defined($data->{'ClientCode'}) || $data->{'ClientCode'} eq "") {
return SOAPResponse(RES_ERROR,ERR_S_PARAM,"Parameter 'ClientCode' invalid");
}
if (!defined($data->{'InvoiceRef'}) || $data->{'InvoiceRef'} eq "") {
return -101;
if (!defined($data->{'Number'}) || $data->{'Number'} eq "") {
return SOAPResponse(RES_ERROR,ERR_S_PARAM,"Parameter 'Number' invalid");
}
if (!defined($data->{'IssueDate'}) || $data->{'IssueDate'} eq "") {
return -101;
return SOAPResponse(RES_ERROR,ERR_S_PARAM,"Parameter 'IssueDate' invalid");
}
if (!defined($data->{'DueDate'}) || $data->{'DueDate'} eq "") {
return -101;
return SOAPResponse(RES_ERROR,ERR_S_PARAM,"Parameter 'DueDate' invalid");
}
my $authInfo = Auth::sessionGetData();
# Do transaction
my $detail;
$detail->{'ClientRef'} = $data->{'ClientRef'};
$detail->{'InvoiceRef'} = $data->{'InvoiceRef'};
$detail->{'ClientCode'} = $data->{'ClientCode'};
$detail->{'Number'} = $data->{'Number'};
$detail->{'ShippingAddress'} = $data->{'ShippingAddress'};
$detail->{'IssueDate'} = $data->{'IssueDate'};
$detail->{'DueDate'} = $data->{'DueDate'};
......@@ -233,100 +235,100 @@ sub createInvoice {
$detail->{'Note'} = $data->{'Note'};
my $res = wiaflos::server::Invoicing::createInvoice($detail);
return $res;
return SOAPResponse(RES_OK,$res);
}
# Link inventory item
# Parameters:
# InvoiceRef - Client invoice number
# InventoryRef - Inventory ref
# Number - Client invoice number
# InventoryCode - Inventory code
# Optional:
# Description - Description
# UnitPrice - Unit price
# Quantity - Quantity
# Discount - Discount %
# Ref - Used by tracked inventory products, this is normally the serial number of the item. Or in any other case
# SerialNumber - Used by tracked inventory products, this is normally the serial number of the item. Or in any other case
# can be used a a batch number, or anything as a matter of fact.
sub linkInventoryItem {
my (undef,$data) = @_;
# Check params
if (!defined($data->{'InvoiceRef'}) || $data->{'InvoiceRef'} eq "") {
return -101;
if (!defined($data->{'Number'}) || $data->{'Number'} eq "") {
return SOAPResponse(RES_ERROR,ERR_S_PARAM,"Parameter 'Number' invalid");
}
if (!defined($data->{'InventoryRef'}) || $data->{'InventoryRef'} eq "") {
return -101;
if (!defined($data->{'InventoryCode'}) || $data->{'InventoryCode'} eq "") {
return SOAPResponse(RES_ERROR,ERR_S_PARAM,"Parameter 'InventoryCode' invalid");
}
my $authInfo = Auth::sessionGetData();
# Do transaction
my $detail;
$detail->{'InvoiceRef'} = $data->{'InvoiceRef'};
$detail->{'InventoryRef'} = $data->{'InventoryRef'};
$detail->{'Number'} = $data->{'Number'};
$detail->{'InventoryCode'} = $data->{'InventoryCode'};
$detail->{'Description'} = $data->{'Description'};
$detail->{'Ref'} = $data->{'Ref'};
$detail->{'SerialNumber'} = $data->{'SerialNumber'};
$detail->{'Quantity'} = $data->{'Quantity'};
$detail->{'Discount'} = $data->{'Discount'};
$detail->{'UnitPrice'} = $data->{'UnitPrice'};
my $res = wiaflos::server::Invoicing::linkItem($detail);
return $res;
return SOAPResponse(RES_OK,$res);
}
# Post client invoice
# Parameters:
# InvoiceRef - Client invoice number
# Number - Client invoice number
sub postInvoice {
my (undef,$data) = @_;
# Check params
if (!defined($data->{'InvoiceRef'}) || $data->{'InvoiceRef'} eq "") {
return -101;
if (!defined($data->{'Number'}) || $data->{'Number'} eq "") {
return SOAPResponse(RES_ERROR,ERR_S_PARAM,"Parameter 'Number' invalid");
}
my $authInfo = Auth::sessionGetData();
# Grab and sanitize data
my $detail;
$detail->{'InvoiceRef'} = $data->{'InvoiceRef'};
$detail->{'Number'} = $data->{'Number'};
my $res = wiaflos::server::Invoicing::postInvoice($detail);
return $res;
return SOAPResponse(RES_OK,$res);
}
# Build client invoice
# Parameters:
# InvoiceRef - Invoice ref
# Number - Invoice ref
# SendTo - Send invoice to here
sub sendInvoice {
my (undef,$data) = @_;
# Check params
if (!defined($data->{'InvoiceRef'}) || $data->{'InvoiceRef'} eq "") {
return -101;
if (!defined($data->{'Number'}) || $data->{'Number'} eq "") {
return SOAPResponse(RES_ERROR,ERR_S_PARAM,"Parameter 'Number' invalid");
}
if (!defined($data->{'SendTo'}) || $data->{'SendTo'} eq "") {
return -101;
return SOAPResponse(RES_ERROR,ERR_S_PARAM,"Parameter 'SendTo' invalid");
}
my $authInfo = Auth::sessionGetData();
# Do transaction
my $detail;
$detail->{'InvoiceRef'} = $data->{'InvoiceRef'};
$detail->{'Number'} = $data->{'Number'};
$detail->{'SendTo'} = $data->{'SendTo'};
my $res = wiaflos::server::Invoicing::sendInvoice($detail);
return $res;
return SOAPResponse(RES_OK,$res);
}
......
......@@ -23,6 +23,7 @@ use warnings;
use Auth;
use wiaflos::constants;
use wiaflos::soap;
use wiaflos::server::Suppliers;
......@@ -61,7 +62,7 @@ sub getSupplier {
# Check params
if (!defined($data->{'Code'}) || $data->{'Code'} eq "") {
return ERR_S_PARAM;
return SOAPResponse(RES_ERROR,ERR_S_PARAM,"Parameter 'Code' invalid");
}
my $authInfo = Auth::sessionGetData();
......@@ -72,7 +73,7 @@ sub getSupplier {
# Grab and sanitize data
my $rawData = wiaflos::server::Suppliers::getSupplier($detail);
if (ref $rawData ne "HASH") {
return $rawData;
return SOAPResponse(RES_ERROR,$rawData,wiaflos::server::Suppliers::Error());
}
# Build result
......@@ -88,7 +89,7 @@ sub getSupplier {
$tmpItem->{'ContactPerson'} = $rawData->{'ContactPerson'};
return $tmpItem;
return SOAPResponse(RES_OK,$tmpItem);
}
......@@ -100,7 +101,7 @@ sub getSuppliers {
# Grab and sanitize data
my $rawData = wiaflos::server::Suppliers::getSuppliers();;
if (ref $rawData ne "ARRAY") {
return $rawData;
return SOAPResponse(RES_ERROR,$rawData,wiaflos::server::Suppliers::Error());
}
# Build result
......@@ -120,7 +121,7 @@ sub getSuppliers {
push(@data,$tmpItem);
}
return \@data;
return SOAPResponse(RES_OK,\@data);
}
......@@ -139,15 +140,15 @@ sub createSupplier {
# 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");
}
......@@ -163,7 +164,11 @@ sub createSupplier {
$detail->{'CreateSubAccount'} = $data->{'CreateSubAccount'};