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

* Major API changes & fixups continue

parent 0e5510b4
......@@ -148,14 +148,14 @@ CREATE TABLE clients (
RegNumber VARCHAR(32), # Company registration number
TaxReference VARCHAR(32), # Tax reference number, VAT/GST ... etc
GLAccID BIGINT UNSIGNED NOT NULL,
GLAccountID BIGINT UNSIGNED NOT NULL,
ContactPerson VARCHAR(128), # Primary contact person
PRIMARY KEY (ID),
UNIQUE KEY(Code),
FOREIGN KEY (GLAccID) REFERENCES gl_accounts(ID)
FOREIGN KEY (GLAccountID) REFERENCES gl_accounts(ID)
) ENGINE=InnoDB;
......@@ -222,14 +222,14 @@ CREATE TABLE suppliers (
RegNumber VARCHAR(32), # Company registration number
TaxReference VARCHAR(32), # Tax reference number, VAT/GST ... etc
GLAccID BIGINT UNSIGNED NOT NULL,
GLAccountID BIGINT UNSIGNED NOT NULL,
ContactPerson VARCHAR(128), # Primary contact person
PRIMARY KEY (ID),
UNIQUE KEY(Code),
FOREIGN KEY (GLAccID) REFERENCES gl_accounts(ID)
FOREIGN KEY (GLAccountID) REFERENCES gl_accounts(ID)
) ENGINE=InnoDB;
......@@ -327,7 +327,7 @@ CREATE TABLE supplier_invoice_items (
SupplierInvoiceID BIGINT UNSIGNED NOT NULL,
InventoryID BIGINT UNSIGNED, # Item we linked to in inventory
GLAccID BIGINT UNSIGNED, # General ledger account ID
GLAccountID BIGINT UNSIGNED, # General ledger account ID
Description VARCHAR(256),
SerialNumber VARCHAR(64), /* If we tracking stock, this will be the serial number */
......@@ -350,7 +350,7 @@ CREATE TABLE supplier_invoice_items (
PRIMARY KEY (ID),
FOREIGN KEY (SupplierInvoiceID) REFERENCES supplier_invoices(ID),
FOREIGN KEY (InventoryID) REFERENCES inventory(ID),
FOREIGN KEY (GLAccID) REFERENCES gl_accounts(ID),
FOREIGN KEY (GLAccountID) REFERENCES gl_accounts(ID),
FOREIGN KEY (TaxTypeID) REFERENCES tax_types(ID)
) ENGINE=InnoDB;
......@@ -364,7 +364,7 @@ CREATE TABLE payments (
ID SERIAL,
SupplierID BIGINT UNSIGNED NOT NULL,
GLAccID BIGINT UNSIGNED NOT NULL, # Sending account
GLAccountID BIGINT UNSIGNED NOT NULL, # Sending account
PaymentNumber VARCHAR(128), # Payment number
......@@ -377,7 +377,7 @@ CREATE TABLE payments (
PRIMARY KEY (ID),
FOREIGN KEY (SupplierID) REFERENCES suppliers(ID),
FOREIGN KEY (GLAccID) REFERENCES gl_accounts(ID),
FOREIGN KEY (GLAccountID) REFERENCES gl_accounts(ID),
FOREIGN KEY (GLTransActID) REFERENCES gl_transactions(ID)
) ENGINE=InnoDB;
......@@ -445,7 +445,7 @@ CREATE TABLE supplier_creditnote_items (
SupplierCreditNoteID BIGINT UNSIGNED NOT NULL,
InventoryID BIGINT UNSIGNED, # Item we linked to in inventory
GLAccID BIGINT UNSIGNED, # General ledger account ID
GLAccountID BIGINT UNSIGNED, # General ledger account ID
Description VARCHAR(256),
SerialNumber VARCHAR(64), /* If we tracking stock, this will be the serial number */
......@@ -465,7 +465,7 @@ CREATE TABLE supplier_creditnote_items (
PRIMARY KEY (ID),
FOREIGN KEY (SupplierCreditNoteID) REFERENCES supplier_creditnotes(ID),
FOREIGN KEY (InventoryID) REFERENCES inventory(ID),
FOREIGN KEY (GLAccID) REFERENCES gl_accounts(ID),
FOREIGN KEY (GLAccountID) REFERENCES gl_accounts(ID),
FOREIGN KEY (TaxTypeID) REFERENCES tax_types(ID)
) ENGINE=InnoDB;
......@@ -489,11 +489,10 @@ CREATE TABLE inventory (
Mode TINYINT UNSIGNED, # For products: 1 = bulk, 2 = track
Description VARCHAR(256) NOT NULL, # Description on system
# BillingDescription VARCHAR(256), # %s = start, %e = end, %s = extra in another table?
IncomeGLAccID BIGINT UNSIGNED NOT NULL,
InventoryGLAccID BIGINT UNSIGNED, # Stock control account
ExpenseGLAccID BIGINT UNSIGNED, # COGS for product
GLIncomeAccountID BIGINT UNSIGNED NOT NULL,
GLAssetAccountID BIGINT UNSIGNED, # Stock control account
GLExpenseAccountID BIGINT UNSIGNED, # COGS for product
Unit VARCHAR(32),
QtyOnHand DECIMAL(12,4), # Set if we dealing with stock items, NULL if service
......@@ -508,9 +507,9 @@ CREATE TABLE inventory (
PRIMARY KEY (ID),
UNIQUE KEY (Code),
FOREIGN KEY (IncomeGLAccID) REFERENCES gl_accounts(ID),
FOREIGN KEY (InventoryGLAccID) REFERENCES gl_accounts(ID),
FOREIGN KEY (ExpenseGLAccID) REFERENCES gl_accounts(ID),
FOREIGN KEY (GLIncomeAccountID) REFERENCES gl_accounts(ID),
FOREIGN KEY (GLAssetAccountID) REFERENCES gl_accounts(ID),
FOREIGN KEY (GLExpenseAccountID) REFERENCES gl_accounts(ID),
FOREIGN KEY (TaxTypeID) REFERENCES tax_types(ID)
) ENGINE=InnoDB;
......@@ -555,7 +554,7 @@ CREATE TABLE tax_types (
Description VARCHAR(256),
TaxGLAccID BIGINT UNSIGNED NOT NULL,
GLAccountID BIGINT UNSIGNED NOT NULL,
TaxRate DECIMAL(4,2) NOT NULL, # Tax rate in percentage
......@@ -646,7 +645,7 @@ CREATE TABLE receipts (
ID SERIAL,
ClientID BIGINT UNSIGNED NOT NULL,
GLAccID BIGINT UNSIGNED NOT NULL, # Sending account
GLAccountID BIGINT UNSIGNED NOT NULL, # Sending account
ReceiptNumber VARCHAR(128), # Receipt number
......@@ -659,7 +658,7 @@ CREATE TABLE receipts (
PRIMARY KEY (ID),
FOREIGN KEY (ClientID) REFERENCES clients(ID),
FOREIGN KEY (GLAccID) REFERENCES gl_accounts(ID),
FOREIGN KEY (GLAccountID) REFERENCES gl_accounts(ID),
FOREIGN KEY (GLTransActID) REFERENCES gl_transactions(ID)
) ENGINE=InnoDB;
......@@ -732,7 +731,7 @@ DROP TABLE IF EXISTS gl_accounts;
CREATE TABLE gl_accounts (
ID SERIAL,
ParentGLAccID BIGINT UNSIGNED,
ParentGLAccountID BIGINT UNSIGNED,
Code BIGINT UNSIGNED NOT NULL,
Name VARCHAR(128) NOT NULL,
......@@ -742,8 +741,8 @@ CREATE TABLE gl_accounts (
PRIMARY KEY (ID),
UNIQUE KEY (Code,ParentGLAccID),
FOREIGN KEY (ParentGLAccID) REFERENCES gl_accounts(ID),
UNIQUE KEY (Code,ParentGLAccountID),
FOREIGN KEY (ParentGLAccountID) REFERENCES gl_accounts(ID),
FOREIGN KEY (FinCatID) REFERENCES gl_fincats(ID),
FOREIGN KEY (RwCatID) REFERENCES gl_rwcats(ID)
) ENGINE=InnoDB;
......@@ -780,13 +779,13 @@ CREATE TABLE gl_entries (
Reference VARCHAR(128),
GLAccID BIGINT UNSIGNED NOT NULL,
GLAccountID BIGINT UNSIGNED NOT NULL,
Amount DECIMAL(10,2) NOT NULL,
PRIMARY KEY (ID),
FOREIGN KEY (GLTransActID) REFERENCES gl_transactions(ID),
FOREIGN KEY (GLAccID) REFERENCES gl_accounts(ID)
FOREIGN KEY (GLAccountID) REFERENCES gl_accounts(ID)
) ENGINE=InnoDB;
......
......@@ -22,6 +22,7 @@ use strict;
use warnings;
use Auth;
use wiaflos::constants;
use wiaflos::server::Inventory;
......@@ -36,10 +37,10 @@ our $pluginInfo = {
sub init {
my $server = shift;
Auth::aclAdd('Inventory','getInventory','Inventory/Show');
Auth::aclAdd('Inventory','createItem','Inventory/Add');
Auth::aclAdd('Inventory','removeItem','Inventory/Remove');
Auth::aclAdd('Inventory','updateItem','Inventory/Update');
Auth::aclAdd('Inventory','getInventoryItem','Inventory/Show');
Auth::aclAdd('Inventory','createInventoryItem','Inventory/Add');
Auth::aclAdd('Inventory','removeInventoryItem','Inventory/Remove');
Auth::aclAdd('Inventory','updateInventoryItem','Inventory/Update');
}
......@@ -51,16 +52,16 @@ sub sanitizeRawItem {
my $tmpItem;
$tmpItem->{'ID'} = $rawItem->{'ID'};
$tmpItem->{'Ref'} = $rawItem->{'Ref'};
$tmpItem->{'Code'} = $rawItem->{'Code'};
$tmpItem->{'Type'} = $rawItem->{'Type'};
$tmpItem->{'Mode'} = $rawItem->{'Mode'};
$tmpItem->{'Description'} = $rawItem->{'Description'};
$tmpItem->{'IncomeGLAccID'} = $rawItem->{'IncomeGLAccID'};
$tmpItem->{'IncomeGLAccRef'} = wiaflos::server::GL::getAccRef($rawItem->{'IncomeGLAccID'});
$tmpItem->{'InventoryGLAccID'} = $rawItem->{'InventoryGLAccID'};
$tmpItem->{'InventoryGLAccRef'} = wiaflos::server::GL::getAccRef($rawItem->{'InventoryGLAccID'});
$tmpItem->{'ExpenseGLAccID'} = $rawItem->{'ExpenseGLAccID'};
$tmpItem->{'ExpenseGLAccRef'} = wiaflos::server::GL::getAccRef($rawItem->{'ExpenseGLAccID'});
$tmpItem->{'GLIncomeAccountID'} = $rawItem->{'GLIncomeAccountID'};
$tmpItem->{'GLIncomeAccountNumber'} = wiaflos::server::GL::getGLAccountNumberFromID($rawItem->{'GLIncomeAccountID'});
$tmpItem->{'GLAssetAccountID'} = $rawItem->{'GLAssetAccountID'};
$tmpItem->{'GLAssetAccountNumber'} = wiaflos::server::GL::getGLAccountNumberFromID($rawItem->{'GLAssetAccountID'});
$tmpItem->{'GLExpenseAccountID'} = $rawItem->{'GLExpenseAccountID'};
$tmpItem->{'GLExpenseAccountNumber'} = wiaflos::server::GL::getGLAccountNumberFromID($rawItem->{'GLExpenseAccountID'});
$tmpItem->{'AvgCostPrice'} = $rawItem->{'AvgCostPrice'};
$tmpItem->{'SellPrice'} = $rawItem->{'SellPrice'};
$tmpItem->{'TaxTypeID'} = $rawItem->{'TaxTypeID'};
......@@ -73,13 +74,13 @@ sub sanitizeRawItem {
# Return list of inventory items
sub getInventory {
sub getInventoryItem {
my $authInfo = Auth::sessionGetData();
# Grab and sanitize data
my $rawData = wiaflos::server::Inventory::getInventory();
my $rawData = wiaflos::server::Inventory::getInventoryItem();
if (ref $rawData ne "ARRAY") {
return -1;
return $rawData;
}
# Build result
......@@ -94,66 +95,66 @@ sub getInventory {
# Create inventory item
# Parameters:
# Ref - Reference
# Code - Inventory item code
# Type - Account type, either "product" or "service"
# Mode - Product mode, "bulk" for bulk item, "track" for tracked item. Ignored for service.
# Desc - Description
# IncomeGLAccRef - GL income account
# InventoryGLAccRef - GL inventory account
# ExpenseGLAccRef - GL expense account
# Description - Description
# GLIncomeAccountNumber - GL income account
# GLAssetAccountNumber - GL asset account
# GLExpenseAccountNumber - GL expense account
# SellPrice - Selling price
# TaxTypeID - Tax type ID
# TaxMode - Tax mode, "incl" or "excl"
# Optional:
# Unit - Unit
# Discountable - Service is either discountable or not, "yes" or "no"
sub createItem {
sub createInventoryItem {
my (undef,$data) = @_;
# Check params
if (!defined($data->{'Ref'}) || $data->{'Ref'} eq "") {
return -101;
if (!defined($data->{'Code'}) || $data->{'Code'} eq "") {
return ERR_S_PARAM;
}
if (!defined($data->{'Type'}) || $data->{'Type'} eq "") {
return -101;
return ERR_S_PARAM;
}
if ($data->{'Type'} eq "product" && (!defined($data->{'Mode'}) || $data->{'Mode'} eq "")) {
return -101;
return ERR_S_USAGE;
}
if (!defined($data->{'Desc'}) || $data->{'Desc'} eq "") {
return -101;
if (!defined($data->{'Description'}) || $data->{'Description'} eq "") {
return ERR_S_PARAM;
}
if (!defined($data->{'IncomeGLAccRef'}) || $data->{'IncomeGLAccRef'} eq "") {
return -101;
if (!defined($data->{'GLIncomeAccountNumber'}) || $data->{'GLIncomeAccountNumber'} eq "") {
return ERR_S_PARAM;
}
if (defined($data->{'InventoryGLAccRef'}) && $data->{'InventoryGLAccRef'} eq "") {
return -101;
if (defined($data->{'GLAssetAccountNumber'}) && $data->{'GLAssetAccountNumber'} eq "") {
return ERR_S_PARAM;
}
if (defined($data->{'ExpenseGLAccRef'}) && $data->{'ExpenseGLAccRef'} eq "") {
return -101;
if (defined($data->{'GLExpenseAccountNumber'}) && $data->{'GLExpenseAccountNumber'} eq "") {
return ERR_S_PARAM;
}
if (!defined($data->{'SellPrice'}) || $data->{'SellPrice'} eq "") {
return -101;
return ERR_S_PARAM;
}
if (!defined($data->{'TaxTypeID'}) || $data->{'TaxTypeID'} < 1) {
return -101;
return ERR_S_PARAM;
}
if (!defined($data->{'TaxMode'}) || $data->{'TaxMode'} eq "") {
return -101;
return ERR_S_PARAM;
}
if (defined($data->{'Discountable'}) && ($data->{'Discountable'} ne "yes" && $data->{'Discountable'} ne "no")) {
return -101;
return ERR_S_PARAM;
}
......@@ -161,19 +162,19 @@ sub createItem {
# Do transaction
my $detail;
$detail->{'Ref'} = $data->{'Ref'};
$detail->{'Code'} = $data->{'Code'};
$detail->{'Type'} = $data->{'Type'};
$detail->{'Mode'} = $data->{'Mode'};
$detail->{'Desc'} = $data->{'Desc'};
$detail->{'IncomeGLAccRef'} = $data->{'IncomeGLAccRef'};
$detail->{'InventoryGLAccRef'} = $data->{'InventoryGLAccRef'};
$detail->{'ExpenseGLAccRef'} = $data->{'ExpenseGLAccRef'};
$detail->{'Description'} = $data->{'Description'};
$detail->{'GLIncomeAccountNumber'} = $data->{'GLIncomeAccountNumber'};
$detail->{'GLAssetAccountNumber'} = $data->{'GLAssetAccountNumber'};
$detail->{'GLExpenseAccountNumber'} = $data->{'GLExpenseAccountNumber'};
$detail->{'SellPrice'} = $data->{'SellPrice'};
$detail->{'TaxTypeID'} = $data->{'TaxTypeID'};
$detail->{'TaxMode'} = $data->{'TaxMode'};
$detail->{'Unit'} = $data->{'Unit'};
$detail->{'Discountable'} = $data->{'Discountable'};
my $res = wiaflos::server::Inventory::createItem($detail);
my $res = wiaflos::server::Inventory::createInventoryItem($detail);
return $res;
}
......@@ -181,22 +182,22 @@ sub createItem {
# Remove inventory item
# Parameters:
# Ref - Ref
sub removeItem {
# Code - Product code
sub removeInventoryItem {
my (undef,$data) = @_;
# Check params
if (!defined($data->{'Ref'}) || $data->{'Ref'} eq "") {
return -101;
if (!defined($data->{'Code'}) || $data->{'Code'} eq "") {
return ERR_S_PARAM;
}
my $authInfo = Auth::sessionGetData();
# Remove item
my $detail;
$detail->{'Ref'} = $data->{'Ref'};
my $res = wiaflos::server::Inventory::removeItem($detail);
$detail->{'Code'} = $data->{'Code'};
my $res = wiaflos::server::Inventory::removeInventoryItem($detail);
return $res;
}
......@@ -204,23 +205,23 @@ sub removeItem {
# Update inventory item
# Parameters:
# Ref - Reference
# Code - Product code
# Optional:
# Desc - Description
# Description - Description
# SellPrice - Selling price
# Unit - Unit
# Discountable - Service is either discountable or not, "yes" or "no"
sub updateItem {
sub updateInventoryItem {
my (undef,$data) = @_;
# Check params
if (!defined($data->{'Ref'}) || $data->{'Ref'} eq "") {
return -101;
if (!defined($data->{'Code'}) || $data->{'Code'} eq "") {
return ERR_S_PARAM;
}
if (defined($data->{'Desc'}) && $data->{'Desc'} eq "") {
return -101;
if (defined($data->{'Description'}) && $data->{'Description'} eq "") {
return ERR_S_PARAM;
}
......@@ -228,12 +229,12 @@ sub updateItem {
# Do transaction
my $detail;
$detail->{'Ref'} = $data->{'Ref'};
$detail->{'Desc'} = $data->{'Desc'};
$detail->{'Code'} = $data->{'Code'};
$detail->{'Description'} = $data->{'Description'};
$detail->{'SellPrice'} = $data->{'SellPrice'};
$detail->{'Unit'} = $data->{'Unit'};
$detail->{'Discountable'} = $data->{'Discountable'};
my $res = wiaflos::server::Inventory::updateItem($detail);
my $res = wiaflos::server::Inventory::updateInventoryItem($detail);
return $res;
}
......
......@@ -22,6 +22,7 @@ use strict;
use warnings;
use Auth;
use wiaflos::constants;
use wiaflos::server::Tax;
......@@ -37,7 +38,7 @@ sub init {
my $server = shift;
Auth::aclAdd('Tax','createType','Tax/Type/Add');
Auth::aclAdd('Tax','createTaxType','Tax/Type/Add');
}
......@@ -45,33 +46,33 @@ sub init {
# Create tax type
# Parameters:
# Desc - Description
# GLAcc - GL account
# Description - Description
# GLAccountNumber - GL account
# Rate - Tax rate
sub createType {
sub createTaxType {
my (undef,$data) = @_;
if (!defined($data->{'Desc'}) || $data->{'Desc'} eq "") {
return -101;
if (!defined($data->{'Description'}) || $data->{'Description'} eq "") {
return ERR_S_PARAM;
}
if (!defined($data->{'GLAcc'}) || $data->{'GLAcc'} eq "") {
return -101;
if (!defined($data->{'GLAccountNumber'}) || $data->{'GLAccountNumber'} eq "") {
return ERR_S_PARAM;
}
if (!defined($data->{'Rate'}) || $data->{'Rate'} eq "") {
return -101;
return ERR_S_PARAM;
}
my $authInfo = Auth::sessionGetData();
# Grab and sanitize data
my $detail;
$detail->{'Desc'} = $data->{'Desc'};
$detail->{'GLAcc'} = $data->{'GLAcc'};
$detail->{'Description'} = $data->{'Description'};
$detail->{'GLAccountNumber'} = $data->{'GLAccountNumber'};
$detail->{'Rate'} = $data->{'Rate'};
my $res = wiaflos::server::Tax::createType($detail);
my $res = wiaflos::server::Tax::createTaxType($detail);
return $res;
}
......
......@@ -31,6 +31,8 @@ plugins=<<EOT
SOAPTest
Clients
GL
Inventory
Tax
EOT
......@@ -23,15 +23,6 @@ package wiaflos::client::cmdline::Clients;
use strict;
use warnings;
# Exporter stuff
require Exporter;
our (@ISA,@EXPORT);
@ISA = qw(Exporter);
@EXPORT = qw(
);
use wiaflos::constants;
use wiaflos::client::misc;
use wiaflos::client::soap;
......@@ -113,23 +104,24 @@ sub list
my $res = soapCall($OUT,"Clients","getClients");
if (ref $res eq "ARRAY") {
print swrite(<<'END', "ID", "Code", "Name", "RegNumber", "TaxRef", "GLAcc");
print $OUT swrite(<<'END', "ID", "Code", "Name", "RegNumber", "TaxRef", "GLAcc");
+========+===========+===============================================+=====================+================+=================+
| @||||| | @|||||||| | @|||||||||||||||||||||||||||||||||||||||||||| | @|||||||||||||||||| | @||||||||||||| | @|||||||||||||| |
+========+===========+===============================================+=====================+================+=================+
END
foreach my $item (@{$res}) {
print swrite(<<'END', $item->{'ID'}, $item->{'Code'}, $item->{'Name'}, defined($item->{'RegNumber'}) ? $item->{'RegNumber'} : '-', defined($item->{'TaxReference'}) ? $item->{'TaxReference'} : '-', $item->{'GLAccNumber'});
print $OUT swrite(<<'END', $item->{'ID'}, $item->{'Code'}, $item->{'Name'}, defined($item->{'RegNumber'}) ? $item->{'RegNumber'} : '-', defined($item->{'TaxReference'}) ? $item->{'TaxReference'} : '-', $item->{'GLAccNumber'});
| @<<<<< | @<<<<<<<< | @<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< | @<<<<<<<<<<<<<<<<<< | @<<<<<<<<<<<<< | @<<<<<<<<<<<<<< |
END
}
print swrite(<<'END');
print $OUT swrite(<<'END');
+========+===========+===============================================+=====================+================+=================+
END
return 0;
} else {
return $res;
}
return $res;
return 0;
}
......@@ -289,7 +281,7 @@ sub show
my $emailAddies = soapCall($OUT,"Clients","getEmailAddresses",$detail);
return $emailAddies if (ref $phones ne "ARRAY");
print("
print($OUT "
ID.....: ".$client->{'ID'}."
Ref....: ".$client->{'Ref'}."
Name...: ".$client->{'Name'}."
......@@ -299,26 +291,26 @@ GLAcc..: ".$client->{'GLAccountNumber'}."
");
foreach my $item (@{$addies}) {
print("
foreach my $item (@{$addies}) {
print($OUT "
Address: ".$item->{'Type'}."
".$item->{'Address'}."
");
}
}
foreach my $item (@{$phones}) {
print("
foreach my $item (@{$phones}) {
print($OUT "
Phone Number: ".$item->{'Type'}."
".$item->{'Number'}."
");
}
}
foreach my $item (@{$emailAddies}) {
print("
foreach my $item (@{$emailAddies}) {
print($OUT "
Email Address: ".$item->{'Type'}."
".$item->{'Address'}."
");
}
}
return 0;
}
......
......@@ -21,14 +21,7 @@
package wiaflos::client::cmdline::Engine;
use strict;
# Exporter stuff
require Exporter;
our (@ISA,@EXPORT);
@ISA = qw(Exporter);
@EXPORT = qw(
);
use warnings;
use wiaflos::client::misc;
use wiaflos::client::soap;
......
......@@ -21,14 +21,7 @@
package wiaflos::client::cmdline::GL;
use strict;