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

* Better sanitization of data in inventory module

* Added product "mode"'s  for tracked and bulk products
* Added tracking of product support to purchasing module
* Added quantity-on-hand for inventory items
* Added avgcostprice to inventory items with mode = bulk
* Added inventory change support to database structure
* Various GL additions and changes
* Added (still not working) posting of supplier invoices
* Fixed up formatting of output in command-line admin interface
parent 3067b2fd
......@@ -207,7 +207,7 @@ CREATE TABLE supplier_invoices (
SubTotal FLOAT, # Add up all items sold
TaxTotal FLOAT, # Add up tax of all items
InvTotal FLOAT NOT NULL, # SubTotal - Tax total
InvTotal FLOAT, # SubTotal + Tax total
# Currency VARCHAR(3),
......@@ -232,10 +232,11 @@ CREATE TABLE supplier_invoice_items (
GLAccID BIGINT UNSIGNED, # General ledger account ID
Description VARCHAR(256),
Quantity INTEGER UNSIGNED NOT NULL,
Ref VARCHAR(64), /* If we tracking stock, this will be the serial number */
Quantity BIGINT UNSIGNED NOT NULL,
Unit VARCHAR(32),
UnitPrice FLOAT NOT NULL,
TotalPrice FLOAT NOT NULL,
Price FLOAT NOT NULL,
Discount FLOAT, # % discount, 0 = none
TaxTypeID BIGINT UNSIGNED, /* NULL for no tax applicable */
......@@ -265,6 +266,7 @@ CREATE TABLE inventory (
SupplierRef VARCHAR(32), # Suppliers code
Type TINYINT UNSIGNED NOT NULL, # 1 = product, 2 = service
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?
......@@ -275,6 +277,8 @@ CREATE TABLE inventory (
Unit VARCHAR(32),
# Currency VARCHAR(3),
QtyOnHand BIGINT, # Set if we dealing with stock items, NULL if service
AvgCostPrice FLOAT, # For bulk products, this is the average cost price
SellPrice FLOAT NOT NULL,
TaxTypeID BIGINT UNSIGNED NOT NULL,
......@@ -292,6 +296,23 @@ CREATE TABLE inventory (
) ENGINE=InnoDB;
DROP TABLE IF EXISTS inventory_changes;
CREATE TABLE inventory_changes (
ID SERIAL,
InventoryID BIGINT UNSIGNED NOT NULL,
GLTransActID BIGINT UNSIGNED NOT NULL,
QtyChange BIGINT NOT NULL,
Ref VARCHAR(64), /* If we tracking stock, this will be the serial number */
PRIMARY KEY (ID),
KEY (InventoryID,Ref),
KEY (GLTransActID,InventoryID)
) ENGINE=InnoDB;
DROP TABLE IF EXISTS tax_types;
CREATE TABLE tax_types (
......@@ -307,7 +328,7 @@ CREATE TABLE tax_types (
PRIMARY KEY (ID)
) ENGINE=InnoDB;
INSERT INTO tax_types (Description,TaxGLAccID,TaxRate) VALUES ('South Africa: Zero Rated @0%','',0);
INSERT INTO tax_types (Description,TaxGLAccID,TaxRate) VALUES ('South Africa: Zero Rated','',0);
INSERT INTO tax_types (Description,TaxGLAccID,TaxRate) VALUES ('South Africa: VAT @14%','',14);
......@@ -337,7 +358,7 @@ CREATE TABLE invoices (
SubTotal FLOAT, # Add up all items sold
TaxTotal FLOAT, # Add up tax of all items
InvTotal FLOAT NOT NULL, # SubTotal + Tax total
InvTotal FLOAT, # SubTotal + Tax total
# Currency VARCHAR(3),
......@@ -516,7 +537,10 @@ INSERT INTO gl_accounts (ParentGLAccID,Ref,Name,FinCatID,RwCatID) VALUES
(@tmp,20,'Petty cash',@fincat_asset,@rwcat_asset);
INSERT INTO gl_accounts (ParentGLAccID,Ref,Name,FinCatID,RwCatID) VALUES
(@tmp,1000,'Clients',@fincat_asset,@rwcat_asset);
(@tmp,98,'Stock control',@fincat_asset,@rwcat_asset);
INSERT INTO gl_accounts (ParentGLAccID,Ref,Name,FinCatID,RwCatID) VALUES
(@tmp,99,'Accounts receivable',@fincat_asset,@rwcat_asset);
......@@ -527,8 +551,13 @@ INSERT INTO gl_accounts (ParentGLAccID,Ref,Name,FinCatID,RwCatID) VALUES
SELECT last_insert_id() INTO @tmp;
INSERT INTO gl_accounts (ParentGLAccID,Ref,Name,FinCatID,RwCatID) VALUES
(@tmp,10,'Accounts payable',@fincat_liability,@rwcat_liability),
(@tmp,20,'Tax payable',@fincat_liability,@rwcat_liability);
(@tmp,10,'Tax payable',@fincat_liability,@rwcat_liability);
SELECT last_insert_id() INTO @tmp2;
INSERT INTO gl_accounts (ParentGLAccID,Ref,Name,FinCatID,RwCatID) VALUES
(@tmp2,10,'VAT control account',@fincat_liability,@rwcat_liability);
INSERT INTO gl_accounts (ParentGLAccID,Ref,Name,FinCatID,RwCatID) VALUES
(@tmp,99,'Accounts payable',@fincat_liability,@rwcat_liability);
INSERT INTO gl_accounts (ParentGLAccID,Ref,Name,FinCatID,RwCatID) VALUES
(@tmp,30,'Banking',@fincat_liability,@rwcat_liability);
......@@ -539,9 +568,6 @@ INSERT INTO gl_accounts (ParentGLAccID,Ref,Name,FinCatID,RwCatID) VALUES
(@tmp2,20,'Credit Card: Joe Soap',@fincat_liability,@rwcat_liability),
(@tmp2,30,'Petrol Card: Joe Soap',@fincat_liability,@rwcat_liability);
INSERT INTO gl_accounts (ParentGLAccID,Ref,Name,FinCatID,RwCatID) VALUES
(@tmp,1000,'Suppliers',@fincat_liability,@rwcat_liability);
......@@ -563,7 +589,13 @@ INSERT INTO gl_accounts (ParentGLAccID,Ref,Name,FinCatID,RwCatID) VALUES
SELECT last_insert_id() INTO @tmp;
INSERT INTO gl_accounts (ParentGLAccID,Ref,Name,FinCatID,RwCatID) VALUES
(@tmp,10,'Sales',@fincat_income,@rwcat_income),
(@tmp,10,'Sales',@fincat_income,@rwcat_income);
SELECT last_insert_id() INTO @tmp2;
INSERT INTO gl_accounts (ParentGLAccID,Ref,Name,FinCatID,RwCatID) VALUES
(@tmp2,10,'Hardware',@fincat_income,@rwcat_income),
(@tmp2,20,'Software',@fincat_income,@rwcat_income);
INSERT INTO gl_accounts (ParentGLAccID,Ref,Name,FinCatID,RwCatID) VALUES
(@tmp,20,'Services',@fincat_income,@rwcat_income);
......
......@@ -123,9 +123,9 @@ my $Inventory_cmds = {
'command' => 'create',
'regex' => 'create',
'desc' => 'Create inventory item',
'help' => 'create ref="<ref>" type="<product or service>" desc="<description>" incomeacc="<income account>" '.
'[inventoryacc="<inventory account>"] [expenseacc="<expense account>"] sellprice="<sell price>" taxtype="<tax type>" '.
'taxmode="<price is incl or excl>" [discountable="<yes or no>"]',
'help' => 'create ref="<ref>" type="<product or service>" [mode="<bulk or track>"] desc="<description>" '.
'incomeacc="<income account>" [inventoryacc="<inventory account>"] [expenseacc="<expense account>"] '.
'sellprice="<sell price>" taxtype="<tax type>" taxmode="<price is incl or excl>" [discountable="<yes or no>"]',
'function' => \&ias::client::cmdline::Inventory::create,
},
{
......@@ -198,6 +198,13 @@ my $Supplier_invoice_cmds = {
'help' => 'show invoiceid="<invoice id>"',
'function' => \&ias::client::cmdline::Purchasing::show,
},
{
'command' => 'post',
'regex' => 'post',
'desc' => 'Post supplier invoice',
'help' => 'post invoiceid="<invoice id>"',
'function' => \&ias::client::cmdline::Purchasing::post,
},
],
};
......
......@@ -36,17 +36,17 @@ sub chart
if (ref $res eq "ARRAY") {
print swrite(<<'END', "ID", "Ref", "Name", "FinCat");
+===========+===================+===================================================================================+======================+
| @|||||||| | @|||||||||||||||| | @|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||| | @||||||||||||||||||| |
+===========+===================+===================================================================================+=======================
+===========+===================+==================================================================================+======================+
| @|||||||| | @|||||||||||||||| | @||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||| | @||||||||||||||||||| |
+===========+===================+==================================================================================+=======================
END
foreach my $account (@{$res}) {
print swrite(<<'END', $account->{'ID'}, $account->{'Ref'}, $account->{'Name'}, $account->{'FinCatIdentifier'} . "/" . $account->{'FinCatDescription'});
| @<<<<<<<< | @<<<<<<<<<<<<<<<< | @<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< | @<<<<<<<<<<<<<<<<<<< |
| @<<<<<<<< | @<<<<<<<<<<<<<<<< | @<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< | @<<<<<<<<<<<<<<<<<<< |
END
}
print swrite(<<'END');
+===========+===================+===================================================================================+======================+
+===========+===================+==================================================================================+======================+
END
} else {
print($OUT " => ERROR(gl:chart): Error $res while executing command\n");
......@@ -74,9 +74,9 @@ sub show
if (ref $res eq "ARRAY") {
print swrite(<<'END', "ID", "Date", "Ref", "Amount", "Balance");
+===========+============+=================================================================================+==============+================+
| @|||||||| | @||||||||| | @|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||| | @||||||||||| | @||||||||||||| |
+===========+============+=================================================================================+==============+================+
+===========+============+================================================================================+==============+================+
| @|||||||| | @||||||||| | @||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||| | @||||||||||| | @||||||||||||| |
+===========+============+================================================================================+==============+================+
END
# Sort data
my @sorted = sort {$a->{'TransDate'} cmp $b->{'TransDate'}} @{$res};
......@@ -86,11 +86,11 @@ END
foreach my $entry (@sorted) {
$balance->badd($entry->{'Amount'});
print swrite(<<'END', $entry->{'ID'}, $entry->{'TransDate'}, $entry->{'Ref'} ? $entry->{'Ref'} : $entry->{'TransRef'}, sprintf('%8.2f',$entry->{'Amount'}),sprintf('%8.2f',$balance));
| @<<<<<<<< | @<<<<<<<<< | @<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< | @>>>>>>>>>>> | @>>>>>>>>>>>>> |
| @<<<<<<<< | @<<<<<<<<< | @<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< | @>>>>>>>>>>> | @>>>>>>>>>>>>> |
END
}
print swrite(<<'END');
+===========+============+=================================================================================+==============+================+
+===========+============+================================================================================+==============+================+
END
} else {
print($OUT " => ERROR(gl:show): Error $res while executing command\n");
......@@ -189,21 +189,21 @@ sub showTransaction
if (ref $res eq "ARRAY") {
print swrite(<<'END', "ID", "GL Account", "Ref", "Amount");
+===========+===================+=========================================================================================+================+
| @|||||||| | @|||||||||||||||| | @|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||| | @||||||||||||| |
+===========+===================+=========================================================================================+================+
+===========+===================+========================================================================================+================+
| @|||||||| | @|||||||||||||||| | @||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||| | @||||||||||||| |
+===========+===================+========================================================================================+================+
END
my $balance = Math::BigFloat->new(0);
foreach my $entry (@{$res}) {
print swrite(<<'END', $entry->{'ID'}, $entry->{'AccRef'}, $entry->{'Ref'} ? $entry->{'Ref'} : "", sprintf('%8.4f',$entry->{'Amount'}));
| @<<<<<<<< | @<<<<<<<<<<<<<<<< | @<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< | @>>>>>>>>>>>>> |
| @<<<<<<<< | @<<<<<<<<<<<<<<<< | @<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< | @>>>>>>>>>>>>> |
END
$balance->badd($entry->{'Amount'});
}
print swrite(<<'END', $balance->bstr());
+===========+===================+=========================================================================================+================+
| Transaction Balance | @>>>>>>>>>>>>> |
+=========================================================================================================================+================+
+===========+===================+========================================================================================+================+
| Transaction Balance | @>>>>>>>>>>>>> |
+========================================================================================================================+================+
END
} else {
print($OUT " => ERROR(gl:trans:show): Error $res while executing command\n");
......@@ -251,17 +251,17 @@ sub listTransactions
if (ref $res eq "ARRAY") {
print swrite(<<'END', "ID", "TransDate", "Ref", "Posted");
+===========+============+========================================================================================================+========+
| @|||||||| | @||||||||| | @||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||| | @||||| |
+===========+============+========================================================================================================+========+
+===========+============+=======================================================================================================+========+
| @|||||||| | @||||||||| | @|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||| | @||||| |
+===========+============+=======================================================================================================+========+
END
foreach my $tran (@{$res}) {
print swrite(<<'END', $tran->{'ID'}, $tran->{'TransDate'}, $tran->{'Ref'}, $tran->{'Posted'});
| @<<<<<<<< | @<<<<<<<<< | @<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< | @<<<<< |
| @<<<<<<<< | @<<<<<<<<< | @<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< | @<<<<< |
END
}
print swrite(<<'END');
+===========+============+========================================================================================================+========+
+===========+============+=======================================================================================================+========+
END
} else {
print($OUT " => ERROR(gl:trans:list): Error $res while executing command\n");
......
......@@ -36,17 +36,17 @@ sub list
if (ref $res eq "ARRAY") {
print swrite(<<'END', "ID", "Ref", "Type", "Description", "Income", "Inventory", "Expense", "SellPrice");
+========+===========+===========+================================================+===============+==============+=============+===========+
| @||||| | @|||||||| | @|||||||| | @||||||||||||||||||||||||||||||||||||||||||||| | @|||||||||||| | @||||||||||| | @|||||||||| | @|||||||| |
+========+===========+===========+================================================+===============+==============+=============+===========+
+========+===========+===========+===============================================+===============+==============+=============+===========+
| @||||| | @|||||||| | @|||||||| | @|||||||||||||||||||||||||||||||||||||||||||| | @|||||||||||| | @||||||||||| | @|||||||||| | @|||||||| |
+========+===========+===========+===============================================+===============+==============+=============+===========+
END
foreach my $item (@{$res}) {
print swrite(<<'END', $item->{'ID'}, $item->{'Ref'}, $item->{'Type'}, $item->{'Description'}, $item->{'IncomeGLAcc'} ? $item->{'IncomeGLAcc'} : '-', defined($item->{'InventoryGLAcc'}) ? $item->{'InventoryGLAcc'} : '-', defined($item->{'ExpenseGLAcc'}) ? $item->{'ExpenseGLAcc'} : '-', sprintf('%.2f',$item->{'SellPrice'}));
| @<<<<< | @<<<<<<<< | @<<<<<<<< | @<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< | @<<<<<<<<<<<< | @<<<<<<<<<<< | @<<<<<<<<<< | @>>>>>>>> |
| @<<<<< | @<<<<<<<< | @<<<<<<<< | @<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< | @<<<<<<<<<<<< | @<<<<<<<<<<< | @<<<<<<<<<< | @>>>>>>>> |
END
}
print swrite(<<'END');
+========+===========+===========+================================================+===============+==============+=============+===========+
+========+===========+===========+===============================================+===============+==============+=============+===========+
END
} else {
print($OUT " => ERROR(inventory:getInventory): Error $res while executing command\n");
......@@ -96,6 +96,7 @@ sub create
my $detail;
$detail->{'Ref'} = $parms->{'ref'};
$detail->{'Type'} = $parms->{'type'};
$detail->{'Mode'} = $parms->{'mode'};
$detail->{'Desc'} = $parms->{'desc'};
$detail->{'IncomeGLAccID'} = $parms->{'incomeacc'};
$detail->{'InventoryGLAccID'} = $parms->{'inventoryacc'};
......
......@@ -36,17 +36,17 @@ sub list
if (ref $res eq "ARRAY") {
print swrite(<<'END', "ID", "InvNum", "SupplrID", "SupplierInvNum", "IssueDate", "DueDate", "TaxTotal", "InvTotal");
+========+===========+===========+================================================+===============+==============+=============+===========+
| @||||| | @|||||||| | @|||||||| | @||||||||||||||||||||||||||||||||||||||||||||| | @|||||||||||| | @||||||||||| | @|||||||||| | @|||||||| |
+========+===========+===========+================================================+===============+==============+=============+===========+
+========+===========+===========+===============================================+===============+==============+=============+===========+
| @||||| | @|||||||| | @|||||||| | @|||||||||||||||||||||||||||||||||||||||||||| | @|||||||||||| | @||||||||||| | @|||||||||| | @|||||||| |
+========+===========+===========+===============================================+===============+==============+=============+===========+
END
foreach my $item (@{$res}) {
print swrite(<<'END', $item->{'ID'}, $item->{'InvoiceNumber'}, $item->{'SupplierID'}, $item->{'SupplierInvNum'}, $item->{'IssueDate'}, defined($item->{'DueDate'}) ? $item->{'DueDate'} : '-', defined($item->{'TaxTotal'}) ? sprintf('%.2f',$item->{'TaxTotal'}) : '-', sprintf('%.2f',$item->{'InvTotal'}));
| @<<<<< | @<<<<<<<< | @<<<<<<<< | @<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< | @<<<<<<<<<<<< | @<<<<<<<<<<< | @<<<<<<<<<< | @>>>>>>>> |
| @<<<<< | @<<<<<<<< | @<<<<<<<< | @<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< | @<<<<<<<<<<<< | @<<<<<<<<<<< | @<<<<<<<<<< | @>>>>>>>> |
END
}
print swrite(<<'END');
+========+===========+===========+================================================+===============+==============+=============+===========+
+========+===========+===========+===============================================+===============+==============+=============+===========+
END
} else {
print($OUT " => ERROR(purchasing:list): Error $res while executing command\n");
......@@ -81,10 +81,6 @@ sub createInvoice
return -202;
}
if (!defined($parms->{'invtotal'})) {
return -202;
}
my $detail;
$detail->{'SupplierID'} = $parms->{'supplierid'};
......@@ -148,6 +144,7 @@ sub linkInventoryItem
$detail->{'SupplierInvoiceID'} = $parms->{'invoiceid'};
$detail->{'InventoryID'} = $parms->{'inventoryid'};
$detail->{'Description'} = $parms->{'desc'};
$detail->{'Ref'} = $parms->{'ref'};
$detail->{'Quantity'} = $parms->{'quantity'};
$detail->{'UnitPrice'} = $parms->{'unitprice'};
$detail->{'TaxTypeID'} = $parms->{'taxtypeid'};
......@@ -210,6 +207,7 @@ sub linkExpenseItem
$detail->{'SupplierInvoiceID'} = $parms->{'invoiceid'};
$detail->{'GLAccID'} = $parms->{'accid'};
$detail->{'Description'} = $parms->{'desc'};
$detail->{'Ref'} = $parms->{'ref'};
$detail->{'Quantity'} = $parms->{'quantity'};
$detail->{'UnitPrice'} = $parms->{'unitprice'};
$detail->{'TaxTypeID'} = $parms->{'taxtypeid'};
......@@ -245,36 +243,63 @@ sub show
my $detail;
$detail->{'SupplierInvoiceID'} = $parms->{'invoiceid'};
my $res = soapCall($OUT,"Purchasing","getInvoice",$detail);
if (ref $res ne "HASH") {
print($OUT " => ERROR(purchasing:show): Error $res while executing getInvoice command\n");
return -1;
}
use Data::Dumper;
print Dumper($res);
my $subTotal = Math::BigFloat->new(0);
my $taxTotal = Math::BigFloat->new(0);
my $invTotal = Math::BigFloat->new(0);
$res = soapCall($OUT,"Purchasing","getInvoiceItems",$detail);
if (ref $res eq "ARRAY") {
print swrite(<<'END', "ID", "Description", "Invent./Exp.", "Unit", "Quantity", "UnitPrice", "Discount", "TaxRate", "TaxAmount");
+========+========================================+===================+========+=========+============+============+=========+=============+
| @||||| | @||||||||||||||||||||||||||||||||||||| | @|||||||||||||||| | @||||| | @|||||| | @||||||||| | @||||||||| | @|||||| | @|||||||||| |
+========+========================================+===================+========+=========+============+============+=========+=============+
print swrite(<<'END', "ID", "Description", "Invt/Exp", "Unit", "Qty", "UnitPrice", "Price", "TaxAmount", "Total");
+========+===========================================+===========+========+========+============+============+=============+==============+
| @||||| | @|||||||||||||||||||||||||||||||||||||||| | @|||||||| | @||||| | @||||| | @||||||||| | @||||||||| | @|||||||||| | @||||||||||| |
+========+===========================================+===========+========+========+============+============+=============+==============+
END
foreach my $item (@{$res}) {
print swrite(<<'END', $item->{'ID'}, $item->{'Description'}, $item->{'InventoryID'}, $item->{'Unit'}, $item->{'Quantity'}, $item->{'UnitPrice'}, $item->{'Discount'}, $item->{'TaxRate'}, $item->{'TaxAmount'});
| @<<<<< | @<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< | @<<<<<<<<<<<<<<<< | @||||| | @>>>>>> | @>>>>>>>>> | @>>>>>>>>> | @>>>>>> | @>>>>>>>>>> |
print swrite(<<'END', $item->{'ID'}, $item->{'Description'}, $item->{'InventoryID'}, defined($item->{'Unit'}) ? $item->{'Unit'} : '-', $item->{'Quantity'}, $item->{'UnitPrice'}, $item->{'Price'}, $item->{'TaxAmount'}, $item->{'TotalPrice'});
| @<<<<< | @<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< | @<<<<<<<< | @||||| | @||||| | @>>>>>>>>> | @>>>>>>>>> | @>>>>>>>>>> | @>>>>>>>>>>> |
END
$subTotal->badd($item->{'Price'});
$taxTotal->badd($item->{'TaxAmount'});
$invTotal->badd($item->{'TotalPrice'});
}
print swrite(<<'END');
+========+========================================+===================+========+=========+============+============+=========+=============+
print swrite(<<'END', $subTotal->bstr(), $taxTotal->bstr(), $invTotal->bstr());
+========+===========================================+===========+========+========+============+============+=============+==============+
| | @>>>>>>>>> | @>>>>>>>>>> | @>>>>>>>>>>> |
+===============================================================================================+============+=============+==============+
END
} else {
print($OUT " => ERROR(purchasing:show): Error $res while executing command\n");
print($OUT " => ERROR(purchasing:show): Error $res while executing getInvoiceItems command\n");
return -1;
}
print Dumper($res);
return 0;
}
# Post invoice
sub post
{
my ($OUT,@args) = @_;
my $parms = parseArgs(@args);
if (!defined($parms->{'invoiceid'})) {
return -202;
}
my $detail;
$detail->{'SupplierInvoiceID'} = $parms->{'invoiceid'};
my $res = soapCall($OUT,"Purchasing","postInvoice",$detail);
return $res;
}
......
......@@ -35,17 +35,17 @@ sub list
if (ref $res eq "ARRAY") {
print swrite(<<'END', "ID", "Ref", "Name", "RegNumber", "TaxRef", "GLAcc");
+========+===========+================================================+=====================+================+=================+
| @||||| | @|||||||| | @||||||||||||||||||||||||||||||||||||||||||||| | @|||||||||||||||||| | @||||||||||||| | @|||||||||||||| |
+========+===========+================================================+=====================+================+=================+
+========+===========+===============================================+=====================+================+=================+
| @||||| | @|||||||| | @|||||||||||||||||||||||||||||||||||||||||||| | @|||||||||||||||||| | @||||||||||||| | @|||||||||||||| |
+========+===========+===============================================+=====================+================+=================+
END
foreach my $item (@{$res}) {
print swrite(<<'END', $item->{'ID'}, $item->{'Ref'}, $item->{'Name'}, defined($item->{'RegNumber'}) ? $item->{'RegNumber'} : '-', defined($item->{'TaxReference'}) ? $item->{'TaxReference'} : '-', $item->{'GLAcc'});
| @<<<<< | @<<<<<<<< | @<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< | @<<<<<<<<<<<<<<<<<< | @<<<<<<<<<<<<< | @<<<<<<<<<<<<<< |
| @<<<<< | @<<<<<<<< | @<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< | @<<<<<<<<<<<<<<<<<< | @<<<<<<<<<<<<< | @<<<<<<<<<<<<<< |
END
}
print swrite(<<'END');
+========+===========+================================================+=====================+================+=================+
+========+===========+===============================================+=====================+================+=================+
END
} else {
print($OUT " => ERROR(suppliers:getsuppliers): Error $res while executing command\n");
......
......@@ -21,6 +21,7 @@ our (@ISA,@EXPORT,@EXPORT_OK);
use ias::server::dblayer;
use ias::server::GL;
use ias::server::Tax qw(taxTypeExists);
use Math::BigFloat;
Math::BigFloat::precision(-4);
......@@ -91,6 +92,113 @@ sub inventoryItemExists
}
# Backend function to build item hash
sub sanitizeRawItem
{
my $rawData = shift;
my $item;
$item->{'ID'} = $rawData->{'ID'};
$item->{'Ref'} = $rawData->{'Ref'};
# Decide what the type should be
if ($rawData->{'Type'} == 1) {
$item->{'Type'} = "product";
# Pull in product mode
if ($rawData->{'Mode'} == 1) {
$item->{'Mode'} = "bulk";
} elsif ($rawData->{'Mode'} == 2) {
$item->{'Mode'} = "track";
} else {
$item->{'Mode'} = "unknown";
}
} elsif ($rawData->{'Type'} == 2) {
$item->{'Type'} = "service";
} else {
$item->{'Type'} = "unknown";
}
$item->{'Description'} = $rawData->{'Description'};
$item->{'IncomeGLAccID'} = $rawData->{'IncomeGLAccID'};
$item->{'IncomeGLAcc'} = ias::server::GL::getAccRef($rawData->{'IncomeGLAccID'});
$item->{'InventoryGLAccID'} = $rawData->{'InventoryGLAccID'};
$item->{'InventoryGLAcc'} = ias::server::GL::getAccRef($rawData->{'InventoryGLAccID'});
$item->{'ExpenseGLAccID'} = $rawData->{'ExpenseGLAccID'};
$item->{'ExpenseGLAcc'} = ias::server::GL::getAccRef($rawData->{'ExpenseGLAccID'});
$item->{'QtyOnHand'} = $rawData->{'QtyOnHand'};
$item->{'AvgCostPrice'} = $rawData->{'AvgCostPrice'};
$item->{'SellPrice'} = $rawData->{'SellPrice'};
$item->{'TaxTypeID'} = $rawData->{'TaxTypeID'};
return $item;
}
# Backend function to adjust stock
sub adjust
{
my ($detail) = @_;
# Pull in inventory item
my $data;
$data->{'ItemID'} = $detail->{'ItemID'};
my $inventoryItem = getInventoryItem($data);
if (ref $inventoryItem ne "HASH") {
return $inventoryItem;
}
# We only adjust products
if ($inventoryItem->{'Type'} ne "product") {
return 0;
}
print(STDERR "Item: ".$detail->{'ItemID'}.", Transaction: ".$detail->{'GLTransActID'}.", QtyChange: ".
$detail->{'QtyChange'}.", Ref: ".$detail->{'Ref'}."\n");
# DBBegin();
#
# # Create inventory adjustment
# my $sql = "
# INSERT INTO inventory_changes
# (InventoryID,GLTransActID,QtyChange,Ref)
# VALUES
# (
# ".DBQuote($detail->{'ItemID'}).",
# ".DBQuote($detail->{'GLTransActID'}).",
# ".DBQuote($detail->{'QtyChange'}).",
# ".DBQuote($detail->{'Ref'})."
# )
# ";
# if (!(my $sth = DBDo($sql)))
# {
# setError(ias::server::dblayer::Error());
# DBRollback();
# return -2;
# }
#
# # Grab last ID
# my $ID = DBLastInsertID("inventory_changes","ID");
if ($inventoryItem->{'Mode'} eq "bulk") {
# Adjust average cost price for item if its bulk
my $avgCostPrice = Math::BigFloat->new($inventoryItem->{'AvgCostPrice'});
$avgCostPrice->bmul($inventoryItem->{'QtyOnHand'});
$avgCostPrice->badd($detail->{'Cost'});
$avgCostPrice->bdiv($inventoryItem->{'QtyOnHand'} + $detail->{'QtyChange'});
print(STDERR "Old: ".$inventoryItem->{'AvgCostPrice'}.", New: ".$avgCostPrice->bstr()."\n");
} else {
print(STDERR "not a bulk item\n");
}
# DBCommit();
#
# return $ID;
}
# Return an array of inventory items
sub getInventory
{
......@@ -100,8 +208,8 @@ sub getInventory
# Return list of inventory items
my $sth = DBSelect("
SELECT
inventory.ID, inventory.Ref, inventory.Type, inventory.Description, inventory.IncomeGLAccID, inventory.InventoryGLAccID,
inventory.ExpenseGLAccID, inventory.SellPrice, inventory.TaxTypeID
inventory.ID, inventory.Ref, inventory.Type, inventory.Mode, inventory.Description, inventory.IncomeGLAccID,
inventory.InventoryGLAccID, inventory.ExpenseGLAccID, inventory.QtyOnHand, inventory.SellPrice, inventory.TaxTypeID
FROM
inventory
");
......@@ -113,36 +221,55 @@ sub getInventory
# Fetch rows
while (my $row = $sth->fetchrow_hashref()) {
my $item;
push(@inventory,sanitizeRawItem($row));
}
$item->{'ID'} = $row->{'ID'};
$item->{'Ref'} = $row->{'Ref'};
DBFreeRes($sth);
return \@inventory;
}