Commit 3f767bc9 authored by Nigel Kukard's avatar Nigel Kukard
Browse files

* Copyright update on all files

* SupplierCreditNotes
- Return only open supplier credit notes by default
- Allow returning of 'open' and 'all' supplier credit notes
- Close creditnote apon full allocation of funds
- Implemented supplier credit note transactions
* SupplierReceipting
- Started work on supplier receipts module, this will preliminary only support generating a receipt against a supplier credit note
* Clients
- Added getClientGLAccountEntries
parent 54380ab2
<?php
# Online GPG file verification script
# Copyright (C) 2007 Nigel Kukard <nkukard@lbsd.net>
# Copyright (C) 2008, LinuxRulz
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
......
......@@ -50,6 +50,7 @@ INSERT INTO soap_caps (GroupID,Capability) VALUES (1,'Engine/Cache/Stats');
INSERT INTO soap_caps (GroupID,Capability) VALUES (1,'Clients/Add');
INSERT INTO soap_caps (GroupID,Capability) VALUES (1,'Clients/Remove');
INSERT INTO soap_caps (GroupID,Capability) VALUES (1,'Clients/Show');
INSERT INTO soap_caps (GroupID,Capability) VALUES (1,'Clients/GL/Show');
/* GL */
INSERT INTO soap_caps (GroupID,Capability) VALUES (1,'GL/Show');
INSERT INTO soap_caps (GroupID,Capability) VALUES (1,'GL/Add');
......@@ -100,6 +101,14 @@ INSERT INTO soap_caps (GroupID,Capability) VALUES (1,'Tax/Type/Add');
INSERT INTO soap_caps (GroupID,Capability) VALUES (1,'SupplierCreditNotes/Add');
INSERT INTO soap_caps (GroupID,Capability) VALUES (1,'SupplierCreditNotes/Show');
INSERT INTO soap_caps (GroupID,Capability) VALUES (1,'SupplierCreditNotes/Post');
/* Supplier Receipting */
INSERT INTO soap_caps (GroupID,Capability) VALUES (1,'SupplierReceipting/Add');
INSERT INTO soap_caps (GroupID,Capability) VALUES (1,'SupplierReceipting/Show');
INSERT INTO soap_caps (GroupID,Capability) VALUES (1,'SupplierReceipting/Post');
INSERT INTO soap_caps (GroupID,Capability) VALUES (1,'SupplierReceipting/Send');
INSERT INTO soap_caps (GroupID,Capability) VALUES (1,'SupplierReceipting/Allocation/Add');
INSERT INTO soap_caps (GroupID,Capability) VALUES (1,'SupplierReceipting/Allocation/Show');
INSERT INTO soap_caps (GroupID,Capability) VALUES (1,'SupplierReceipting/Allocation/Post');
......@@ -521,7 +530,7 @@ CREATE TABLE supplier_invoice_transactions (
FOREIGN KEY (SupplierInvoiceID) REFERENCES supplier_invoices(ID),
FOREIGN KEY (SupplierCreditNoteID) REFERENCES supplier_creditnotes(ID),
FOREIGN KEY (PaymentAllocationID) REFERENCES payment_allocations(ID)
);
) @CREATE_TABLE_SUFFIX@;
CREATE TABLE supplier_invoice_items (
......@@ -648,6 +657,8 @@ CREATE TABLE supplier_creditnotes (
GLTransactionID @SERIAL_REF_TYPE@, /* Not null if posted */
Closed SMALLINT NOT NULL DEFAULT '0', /* '1' if the credit note is fully allocated */
FOREIGN KEY (SupplierID) REFERENCES suppliers(ID),
FOREIGN KEY (SupplierInvoiceID) REFERENCES supplier_invoices(ID),
......@@ -710,6 +721,71 @@ CREATE TABLE supplier_creditnote_item_tracking (
FOREIGN KEY (InventoryTrackingID) REFERENCES inventory_tracking(ID)
) @CREATE_TABLE_SUFFIX@;
CREATE TABLE supplier_creditnote_transactions (
ID @SERIAL_TYPE@,
SupplierCreditNoteID @SERIAL_REF_TYPE@ NOT NULL,
SupplierInvoiceTransactionID @SERIAL_REF_TYPE@,
SupplierReceiptAllocationID @SERIAL_REF_TYPE@,
Amount DECIMAL(10,2) NOT NULL,
FOREIGN KEY (SupplierCreditNoteID) REFERENCES supplier_creditnotes(ID),
FOREIGN KEY (SupplierInvoiceTransactionID) REFERENCES supplier_invoice_transactions(ID),
FOREIGN KEY (SupplierReceiptAllocationID) REFERENCES supplier_receipt_allocations(ID)
) @CREATE_TABLE_SUFFIX@;
/*
* S U P P L I E R R E C E I P T S
*/
CREATE TABLE supplier_receipts (
ID @SERIAL_TYPE@,
SupplierID @SERIAL_REF_TYPE@ NOT NULL,
GLAccountID @SERIAL_REF_TYPE@ NOT NULL, /* Sending account */
Number VARCHAR(128), /* Receipt number */
TransactionDate DATE NOT NULL,
Reference VARCHAR(128), /* Reference on account statement */
Amount DECIMAL(10,2) NOT NULL,
GLTransactionID @SERIAL_REF_TYPE@, /* Set if posted */
Closed SMALLINT NOT NULL DEFAULT '0',
FOREIGN KEY (SupplierID) REFERENCES suppliers(ID),
FOREIGN KEY (GLAccountID) REFERENCES gl_accounts(ID),
FOREIGN KEY (GLTransactionID) REFERENCES gl_transactions(ID)
) @CREATE_TABLE_SUFFIX@;
CREATE TABLE supplier_receipt_allocations (
ID @SERIAL_TYPE@,
SupplierReceiptID @SERIAL_REF_TYPE@ NOT NULL,
SupplierCreditNoteID @SERIAL_REF_TYPE@ NOT NULL,
SupplierCreditNoteTransactionID @SERIAL_REF_TYPE@,
Amount DECIMAL(10,2),
FOREIGN KEY (SupplierReceiptID) REFERENCES supplier_receipts(ID),
FOREIGN KEY (SupplierCreditNoteID) REFERENCES supplier_creditnotes(ID),
FOREIGN KEY (SupplierCreditNoteTransactionID) REFERENCES supplier_creditnote_transactions(ID)
) @CREATE_TABLE_SUFFIX@;
......@@ -811,7 +887,7 @@ CREATE TABLE invoice_transactions (
FOREIGN KEY (InvoiceID) REFERENCES invoices(ID),
/* FOREIGN KEY (CreditNoteID) REFERENCES creditnotes(ID), */
FOREIGN KEY (ReceiptAllocationID) REFERENCES receipt_allocations(ID)
);
) @CREATE_TABLE_SUFFIX@;
......@@ -854,7 +930,8 @@ CREATE TABLE receipt_allocations (
FOREIGN KEY (ReceiptID) REFERENCES receipts(ID),
FOREIGN KEY (InvoiceID) REFERENCES invoices(ID)
FOREIGN KEY (InvoiceID) REFERENCES invoices(ID),
FOREIGN KEY (InvoiceTransactionID) REFERENCES invoice_transactions(ID)
) @CREATE_TABLE_SUFFIX@;
......
# SOAP authentication functions
# Copyright (C) 2005-2007 Nigel Kukard <nkukard@lbsd.net>
# Copyright (C) 2008, LinuxRulz
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
......
# SOAP interface to Clients module
# Copyright (C) 2007 Nigel Kukard <nkukard@lbsd.net>
# Copyright (C) 2008, LinuxRulz
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
......@@ -50,6 +51,8 @@ sub init {
Auth::aclAdd('Clients','linkClientPhoneNumber','Clients/Add');
Auth::aclAdd('Clients','removeClient','Clients/Remove');
Auth::aclAdd('Clients','getClientGLAccountEntries','Clients/GL/Show');
}
......@@ -442,6 +445,48 @@ sub removeClient {
}
# Return list of client GL account entries
# Parameters:
# AccountNumber - GL account number
sub getClientGLAccountEntries {
my (undef,$data) = @_;
if (!defined($data->{'Code'}) || $data->{'Code'} eq "") {
return SOAPResponse(RES_ERROR,ERR_S_PARAM,"Parameter 'Code' invalid");
}
my $authInfo = Auth::sessionGetData();
# Grab and sanitize data
my $detail;
$detail->{'Code'} = $data->{'Code'};
my $rawData = wiaflos::server::Clients::getGLAccountEntries($detail);
if (ref $rawData ne "ARRAY") {
return SOAPResponse(RES_ERROR,$rawData,wiaflos::server::GL::Error());
}
# Build result
my @data;
foreach my $item (@{$rawData}) {
my $tmpItem;
$tmpItem->{'ID'} = $item->{'ID'};
$tmpItem->{'TransactionID'} = $item->{'TransactionID'};
$tmpItem->{'Reference'} = $item->{'Reference'};
$tmpItem->{'TransactionDate'} = $item->{'TransactionDate'};
$tmpItem->{'Amount'} = $item->{'Amount'};
$tmpItem->{'TransactionReference'} = $item->{'TransactionReference'};
push(@data,$tmpItem);
}
return SOAPResponse(RES_OK,\@data);
}
......
# SOAP interface to Engine module
# Copyright (C) 2007 Nigel Kukard <nkukard@lbsd.net>
# Copyright (C) 2008, LinuxRulz
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
......
# SOAP interface to GL module
# Copyright (C) 2006-2007 Nigel Kukard <nkukard@lbsd.net>
# Copyright (C) 2008, LinuxRulz
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
......
# SOAP interface to Inventory module
# Copyright (C) 2007 Nigel Kukard <nkukard@lbsd.net>
# Copyright (C) 2008, LinuxRulz
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
......
# SOAP interface to Invoicing module
# Copyright (C) 2007 Nigel Kukard <nkukard@lbsd.net>
# Copyright (C) 2008, LinuxRulz
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
......
# SOAP interface to Payments module
# Copyright (C) 2007 Nigel Kukard <nkukard@lbsd.net>
# Copyright (C) 2008, LinuxRulz
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
......
# SOAP interface to Purchasing module
# Copyright (C) 2007 Nigel Kukard <nkukard@lbsd.net>
# Copyright (C) 2008, LinuxRulz
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
......@@ -52,6 +53,8 @@ sub init {
# Return list of supplier invoices
# Optional:
# Type - "paid" and "all"
sub getSupplierInvoices {
my (undef,$data) = @_;
......
# SOAP interface to Receipting module
# Copyright (C) 2007 Nigel Kukard <nkukard@lbsd.net>
# Copyright (C) 2008, LinuxRulz
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
......
# SOAP test functions
# Copyright (C) 2005-2007 Nigel Kukard <nkukard@lbsd.net>
# Copyright (C) 2008, LinuxRulz
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
......
# SOAP interface to Statements module
# Copyright (C) 2007 Nigel Kukard <nkukard@lbsd.net>
# Copyright (C) 2008, LinuxRulz
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
......
# SOAP interface to SupplierCreditNotes module
# Copyright (C) 2007 Nigel Kukard <nkukard@lbsd.net>
# Copyright (C) 2008, LinuxRulz
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
......@@ -52,11 +53,18 @@ sub init {
# Return list of supplier credit notes
# Optional:
# Type - "open" and "all"
sub getSupplierCreditNotes {
my (undef,$data) = @_;
my $authInfo = Auth::sessionGetData();
# Grab and sanitize data
my $rawData = wiaflos::server::SupplierCreditNotes::getSupplierCreditNotes();
my $detail;
$detail->{'Type'} = $data->{'Type'};
my $rawData = wiaflos::server::SupplierCreditNotes::getSupplierCreditNotes($detail);
if (ref $rawData ne "ARRAY") {
return SOAPResponse(RES_ERROR,$rawData,wiaflos::server::SupplierCreditNotes::Error());
}
......@@ -84,6 +92,8 @@ sub getSupplierCreditNotes {
$tmpItem->{'GLTransactionID'} = $item->{'GLTransactionID'};
$tmpItem->{'Posted'} = $item->{'Posted'};
$tmpItem->{'Closed'} = $item->{'Closed'};
push(@data,$tmpItem);
}
......
# SOAP interface to SupplierReceipting module
# Copyright (C) 2008, LinuxRulz
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along
# with this program; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
package SupplierReceipting;
use strict;
use warnings;
use Auth;
use wiaflos::constants;
use wiaflos::soap;
use wiaflos::server::SupplierReceipting;
# Plugin info
our $pluginInfo = {
Name => "SupplierReceipting",
Init => \&init,
};
# Initialize module
sub init {
my $server = shift;
Auth::aclAdd('SupplierReceipting','createSupplierReceipt','SupplierReceipting/Add');
Auth::aclAdd('SupplierReceipting','getSupplierReceipts','SupplierReceipting/Show');
Auth::aclAdd('SupplierReceipting','getSupplierReceipt','SupplierReceipting/Show');
Auth::aclAdd('SupplierReceipting','postSupplierReceipt','SupplierReceipting/Post');
Auth::aclAdd('SupplierReceipting','sendSupplierReceipt','SupplierReceipting/Send');
Auth::aclAdd('SupplierReceipting','createSupplierReceiptAllocation','SupplierReceipting/Allocation/Add');
Auth::aclAdd('SupplierReceipting','getSupplierReceiptAllocations','SupplierReceipting/Allocation/Show');
Auth::aclAdd('SupplierReceipting','postSupplierReceiptAllocation','SupplierReceipting/Allocation/Post');
}
# Create receipt
# Parameters:
# SupplierCode - Supplier code
# GLAccountNumber - GL account where money was paid from
# Number - Receipt number
# Date - Date of receipt
# Reference - GL account entry reference (bank statement reference for example)
# Amount - Amount
sub createSupplierReceipt {
my (undef,$data) = @_;
# Check params
if (!defined($data->{'SupplierCode'}) || $data->{'SupplierCode'} eq "") {
return SOAPResponse(RES_ERROR,ERR_S_PARAM,"Parameter 'SupplierCode' invalid");
}
if (!defined($data->{'GLAccountNumber'}) || $data->{'GLAccountNumber'} eq "") {
return SOAPResponse(RES_ERROR,ERR_S_PARAM,"Parameter 'GLAccountNumber' invalid");
}
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 SOAPResponse(RES_ERROR,ERR_S_PARAM,"Parameter 'Date' invalid");
}
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 SOAPResponse(RES_ERROR,ERR_S_PARAM,"Parameter 'Amount' invalid");
}
my $authInfo = Auth::sessionGetData();
# Do transaction
my $detail;
$detail->{'SupplierCode'} = $data->{'SupplierCode'};
$detail->{'GLAccountNumber'} = $data->{'GLAccountNumber'};
$detail->{'Number'} = $data->{'Number'};
$detail->{'Date'} = $data->{'Date'};
$detail->{'Reference'} = $data->{'Reference'};
$detail->{'Amount'} = $data->{'Amount'};
my $res = wiaflos::server::SupplierReceipting::createSupplierReceipt($detail);
if ($res < 1) {
return SOAPResponse(RES_ERROR,$res,wiaflos::server::SupplierReceipting::Error());
}
return SOAPResponse(RES_OK,$res);
}
# Return list of receipts
sub getSupplierReceipts {
my (undef,$data) = @_;
my $authInfo = Auth::sessionGetData();
# Grab and sanitize data
my $detail;
$detail->{'Type'} = $data->{'Type'};
my $rawData = wiaflos::server::SupplierReceipting::getSupplierReceipts($detail);
if (ref $rawData ne "ARRAY") {
return SOAPResponse(RES_ERROR,$rawData,wiaflos::server::SupplierReceipting::Error());
}
# Build result
my @data;
foreach my $item (@{$rawData}) {
my $tmpItem;
$tmpItem->{'ID'} = $item->{'ID'};
$tmpItem->{'SupplierID'} = $item->{'SupplierID'};
$tmpItem->{'SupplierCode'} = $item->{'SupplierCode'};
$tmpItem->{'GLAccountID'} = $item->{'GLAccountID'};
$tmpItem->{'GLAccountNumber'} = $item->{'GLAccountNumber'};
$tmpItem->{'Number'} = $item->{'Number'};
$tmpItem->{'TransactionDate'} = $item->{'TransactionDate'};
$tmpItem->{'Reference'} = $item->{'Reference'};
$tmpItem->{'Amount'} = $item->{'Amount'};
$tmpItem->{'GLTransactionID'} = $item->{'GLTransactionID'};
$tmpItem->{'Posted'} = $item->{'Posted'};
$tmpItem->{'Closed'} = $item->{'Closed'};
push(@data,$tmpItem);
}
return SOAPResponse(RES_OK,\@data);
}
# Return a receipt
sub getSupplierReceipt {
my (undef,$data) = @_;
my $authInfo = Auth::sessionGetData();
# Grab and sanitize data
my $detail;
$detail->{'Number'} = $data->{'Number'};
$detail->{'ID'} = $data->{'ID'};
my $rawData = wiaflos::server::SupplierReceipting::getSupplierReceipt($detail);
if (ref $rawData ne "HASH") {
return SOAPResponse(RES_ERROR,$rawData,wiaflos::server::SupplierReceipting::Error());
}
my $tmpItem;
$tmpItem->{'ID'} = $rawData->{'ID'};
$tmpItem->{'SupplierID'} = $rawData->{'SupplierID'};
$tmpItem->{'SupplierCode'} = $rawData->{'SupplierCode'};
$tmpItem->{'GLAccountID'} = $rawData->{'GLAccountID'};
$tmpItem->{'GLAccountNumber'} = $rawData->{'GLAccountNumber'};
$tmpItem->{'Number'} = $rawData->{'Number'};
$tmpItem->{'TransactionDate'} = $rawData->{'TransactionDate'};
$tmpItem->{'Reference'} = $rawData->{'Reference'};
$tmpItem->{'Amount'} = $rawData->{'Amount'};
$tmpItem->{'GLTransactionID'} = $rawData->{'GLTransactionID'};
$tmpItem->{'Posted'} = $rawData->{'Posted'};
$tmpItem->{'Closed'} = $rawData->{'Closed'};
return SOAPResponse(RES_OK,$tmpItem);
}
# Post receipt
# Parameters:
# Number - Supplier receipt number
sub postSupplierReceipt
{
my (undef,$data) = @_;
# Check params
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->{'Number'} = $data->{'Number'};
my $res = wiaflos::server::SupplierReceipting::postSupplierReceipt($detail);
if ($res < 0) {
return SOAPResponse(RES_ERROR,$res,wiaflos::server::SupplierReceipting::Error());
}
return SOAPResponse(RES_OK,$res);
}
# Post allocation
# Parameters:
# ID - Allocation ID to post
sub postSupplierReceiptAllocation
{
my (undef,$data) = @_;
# Check params
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->{'ID'} = $data->{'ID'};
my $res = wiaflos::server::SupplierReceipting::postSupplierReceiptAllocation($detail);
if ($res < 0) {
return SOAPResponse(RES_ERROR,$res,wiaflos::server::SupplierReceipting::Error());
}
return SOAPResponse(RES_OK,$res);
}
# Create allocation
# Parameters:
# SupplierReceiptNumber - Receipt number
# SupplierCreditNoteNumber - Invoice number
# Amount - Amount
sub createSupplierReceiptAllocation {
my (undef,$data) = @_;
# Check params
if (!defined($data->{'SupplierReceiptNumber'}) || $data->{'SupplierReceiptNumber'} eq "") {
return SOAPResponse(RES_ERROR,ERR_S_PARAM,"Parameter 'SupplierReceiptNumber' invalid");
}
if (!defined($data->{'SupplierCreditNoteNumber'}) || $data->{'SupplierCreditNoteNumber'} eq "") {
return SOAPResponse(RES_ERROR,ERR_S_PARAM,"Parameter 'SupplierCreditNoteNumber' invalid");
}
if (!defined($data->{'Amount'}) || $data->{'Amount'} eq "") {
return SOAPResponse(RES_ERROR,ERR_S_PARAM,"Parameter 'Amount' invalid");
}
my $authInfo = Auth::sessionGetData();
# Do transaction
my $detail;
$detail->{'SupplierReceiptNumber'} = $data->{'SupplierReceiptNumber'};
$detail->{'SupplierCreditNoteNumber'} = $data->{'SupplierCreditNoteNumber'};
$detail->{'Amount'} = $data->{'Amount'};
my $res = wiaflos::server::SupplierReceipting::createSupplierReceiptAllocation($detail);
if ($res < 1) {
return SOAPResponse(RES_ERROR,$res,wiaflos::server::SupplierReceipting::Error());
}
return SOAPResponse(RES_OK,$res);
}
# Return list of receipt allocations
sub getSupplierReceiptAllocations {
my (undef,$data) = @_;
# Check params
if (!defined($data->{'SupplierReceiptNumber'}) || $data->{'SupplierReceiptNumber'} eq "") {
return SOAPResponse(RES_ERROR,ERR_S_PARAM,"Parameter 'SupplierReceiptNumber' invalid");