[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
SF.net SVN: ledger-smb:[3000] trunk
- Subject: SF.net SVN: ledger-smb:[3000] trunk
- From: ..hidden..
- Date: Wed, 05 May 2010 18:48:24 +0000
Revision: 3000
http://ledger-smb.svn.sourceforge.net/ledger-smb/?rev=3000&view=rev
Author: aurynn_cmd
Date: 2010-05-05 18:48:24 +0000 (Wed, 05 May 2010)
Log Message:
-----------
Finalizing schema support in LedgerSMB.pm.
Modifications to company.sql to change the delete/insert to a more correct update, for better tracking in the Auditing add-on.
Minor whitespace cleanup in taxform.pl
Cancel support in admin.pl
Bugfix for deleting a location in admin.pl - change from POST check to a GET check.
Adding new information methods to DBObject/Company.pm
Tax form DB test cases
Modified Paths:
--------------
trunk/LedgerSMB/DBObject/Company.pm
trunk/LedgerSMB/DBObject/Location.pm
trunk/LedgerSMB/DBObject/User.pm
trunk/LedgerSMB/ScriptLib/Company.pm
trunk/LedgerSMB.pm
trunk/UI/Admin/edit_user.html
trunk/scripts/admin.pl
trunk/scripts/taxform.pl
trunk/sql/Pg-database.sql
trunk/sql/modules/1099_reports.sql
trunk/sql/modules/Company.sql
trunk/sql/modules/EndOfYear.sql
trunk/sql/modules/Entity.sql
trunk/sql/modules/Roles.sql
trunk/sql/modules/test/System.sql
trunk/t/43-dbtest.t
Added Paths:
-----------
trunk/sql/modules/test/Taxform.sql
Modified: trunk/LedgerSMB/DBObject/Company.pm
===================================================================
--- trunk/LedgerSMB/DBObject/Company.pm 2010-05-05 18:09:08 UTC (rev 2999)
+++ trunk/LedgerSMB/DBObject/Company.pm 2010-05-05 18:48:24 UTC (rev 3000)
@@ -40,7 +40,7 @@
=item save()
-This stores the company record including a credit accoun tin the database.
+This stores the company record including a credit account in the database.
TODO: Separate company from credit account storage.
@@ -236,6 +236,33 @@
$self->merge($ref);
}
+sub account {
+
+ my ($self, $account) = @_;
+
+ $self->set_entity_class();
+ my ($account) = $self->exec_method(funcname => 'company__get_account');
+}
+
+sub accounts {
+
+ my ($self) = @_;
+
+ $self->set_entity_class();
+ @{$self->{accounts}} = $self->exec_method(funcname => 'company__get_all_accounts');
+}
+
+sub address {
+
+ my ($self, $id) = @_;
+
+ for my $loc (@{ $self->{locations} }) {
+ if ($loc->{id} == $id) {
+ return $loc;
+ }
+ }
+}
+
sub get {
my $self = shift @_;
Modified: trunk/LedgerSMB/DBObject/Location.pm
===================================================================
--- trunk/LedgerSMB/DBObject/Location.pm 2010-05-05 18:09:08 UTC (rev 2999)
+++ trunk/LedgerSMB/DBObject/Location.pm 2010-05-05 18:48:24 UTC (rev 3000)
@@ -17,13 +17,13 @@
my ($ret) = $self->exec_method(funcname=>$type."__save_location", args=>[
$self->{user_id}, # entity_id
$self->{location_id}, # location_id
- 3, # location_class, currently being set to "shipping"
- $self->{address1},
- $self->{address2},
- $self->{address3}, # address info
+ $self->{location_class}, # location class, for _to_contact
+ $self->{line_one},
+ $self->{line_two},
+ $self->{line_three}, # address info
$self->{city}, # city
$self->{state}, # state/province
- $self->{zipcode},
+ $self->{mail_code},
$self->{country} # obviously, country.
]);
$self->{id} = $ret->{$type."__save_location"};
@@ -34,14 +34,14 @@
sub delete {
my $self = shift @_;
+ my $type = shift @_;
my $id = shift @_;
my $e_id = shift @_;
- my $type = shift @_;
+ # e_id is an entity
+ # id is the location_id
- # e_id is an entity of some variety
-
if (!$id && !$self->{location_id}) {
$self->error("Must call delete with an ID...");
}
Modified: trunk/LedgerSMB/DBObject/User.pm
===================================================================
--- trunk/LedgerSMB/DBObject/User.pm 2010-05-05 18:09:08 UTC (rev 2999)
+++ trunk/LedgerSMB/DBObject/User.pm 2010-05-05 18:48:24 UTC (rev 3000)
@@ -298,5 +298,5 @@
}
+1;
-1;
Modified: trunk/LedgerSMB/ScriptLib/Company.pm
===================================================================
--- trunk/LedgerSMB/ScriptLib/Company.pm 2010-05-05 18:09:08 UTC (rev 2999)
+++ trunk/LedgerSMB/ScriptLib/Company.pm 2010-05-05 18:48:24 UTC (rev 3000)
@@ -3,6 +3,8 @@
use LedgerSMB::DBObject::Customer;
use LedgerSMB::DBObject::Vendor;
+use Data::Dumper;
+
my $ec_labels = {
1 => 'Vendor',
2 => 'Customer',
@@ -579,7 +581,7 @@
$company->save_contact();
}
$company->get;
- _render_main_screen($company );
+ _render_main_screen( $company );
}
=pod
Modified: trunk/LedgerSMB.pm
===================================================================
--- trunk/LedgerSMB.pm 2010-05-05 18:09:08 UTC (rev 2999)
+++ trunk/LedgerSMB.pm 2010-05-05 18:48:24 UTC (rev 3000)
@@ -646,6 +646,7 @@
my $self = shift @_;
my %args = @_;
my $procname = $args{procname};
+ my $schema = $args{schema};
my @call_args;
@call_args = @{ $args{args} } if defined $args{args};
my $order_by = $args{order_by};
@@ -657,11 +658,17 @@
}
$procname = $self->{dbh}->quote_identifier($procname);
+ # Add the test for whether the schema is something useful.
+
+ $schema = $schema || $LedgerSMB::Sysconfig::db_namespace;
+
+ $schema = $self->{dbh}->quote_identifier($schema);
+
for ( 1 .. scalar @call_args ) {
$argstr .= "?, ";
}
$argstr =~ s/\, $//;
- my $query = "SELECT * FROM $procname()";
+ my $query = "SELECT * FROM $schema.$procname()";
if ($order_by){
$query .= " ORDER BY $order_by";
}
Modified: trunk/UI/Admin/edit_user.html
===================================================================
--- trunk/UI/Admin/edit_user.html 2010-05-05 18:09:08 UTC (rev 2999)
+++ trunk/UI/Admin/edit_user.html 2010-05-05 18:48:24 UTC (rev 3000)
@@ -179,6 +179,7 @@
<?lsmb IF location?>
<input type="submit" value="Edit Location">
<input type="hidden" name="location_id" value="<?lsmb location.id?>"/>
+ <input type="submit" value="Cancel" name="cancel"/>
<?lsmb ELSE?>
<input type="submit" value="Save Location">
<?lsmb END?>
@@ -239,6 +240,7 @@
<?lsmb IF contact?>
<input type="submit" value="Edit Contact">
<input type="hidden" name="contact_id" value="<?lsmb contact.id?>"/>
+ <input type="submit" value="Cancel" name="cancel"/>
<?lsmb ELSE?>
<input type="submit" value="Save Contact">
<?lsmb END?>
Modified: trunk/scripts/admin.pl
===================================================================
--- trunk/scripts/admin.pl 2010-05-05 18:09:08 UTC (rev 2999)
+++ trunk/scripts/admin.pl 2010-05-05 18:48:24 UTC (rev 3000)
@@ -281,6 +281,12 @@
# Only ever a post, but check anyway
if ($request->type eq "POST") {
+ if ($request->{cancel}) {
+
+ # If we have a cancel request, we just go back to edit_page.
+ return __edit_page($request);
+ }
+
# We have a contact ID, ie, something we made up.
my $c_id = $request->{contact_id};
my $u_id = $request->{user_id};
@@ -305,6 +311,12 @@
# Only ever a post, but check anyway
if ($request->type eq "POST") {
+ if ($request->{cancel}) {
+
+ # If we have a cancel request, we just go back to edit_page.
+ return __edit_page($request);
+ }
+
# We have a contact ID, ie, something we made up.
my $c_id = $request->{contact_id};
my $u_id = $request->{user_id};
@@ -331,6 +343,18 @@
# Only ever a post, but check anyway
if ($request->type eq "POST") {
+ if ($request->{cancel}) {
+
+ # If we have a cancel request, we just go back to edit_page.
+ return __edit_page($request);
+ }
+
+ if ($request->{cancel}) {
+
+ # If we have a cancel request, we just go back to edit_page.
+ return __edit_page($request);
+ }
+
my $u_id = $request->{user_id}; # this is an entity_id
my $user_obj = LedgerSMB::DBObject::User->new(base=>$request, copy=>'user_id');
my $location = LedgerSMB::DBObject::Location->new(base=>$request, copy=>'all');
@@ -348,30 +372,7 @@
my $id = $location->save("person");
# Done and done.
- my $admin = LedgerSMB::DBObject::Admin->new(base=>$request, copy=>'user_id');
-
-
-
- my @all_roles = $admin->get_roles();
-
- my $template = LedgerSMB::Template->new(
- user => $user,
- template => 'Admin/edit_user',
- language => $user->{language},
- format => 'HTML',
- path=>'UI'
- );
- $template->render(
- {
- user=>$user_obj,
- roles=>@all_roles,
- user_roles=>$user_obj->{roles},
- salutations=>$admin->get_salutations(),
- locations=>$location->get_all($u_id,"person"),
- location=>$location->get($id),
- countries=>$admin->get_countries(),
- }
- );
+ __edit_page($request,{location=>$location});
}
}
@@ -380,18 +381,19 @@
my $request = shift @_;
- # Only ever a post, but check anyway
- if ($request->type eq "POST") {
+ # Having delete come over GET perhaps isn't the best technique.
+
+ if ($request->type eq "GET") {
my $l_id = $request->{location_id};
my $u_id = $request->{user_id};
-
+ my $user_obj = LedgerSMB::DBObject::User->new(base=>$request, copy=>'user_id');
my $location = LedgerSMB::DBObject::Location->new(base=>$request, copy=>"location_id");
- $location->person_delete($l_id,$u_id);
+ $location->delete("person",$l_id,$user_obj->{user}->{entity_id});
# Boom. Done.
# Now, just call the main edit user page.
- edit_user($request);
+ __edit_page($request);
}
}
Modified: trunk/scripts/taxform.pl
===================================================================
--- trunk/scripts/taxform.pl 2010-05-05 18:09:08 UTC (rev 2999)
+++ trunk/scripts/taxform.pl 2010-05-05 18:48:24 UTC (rev 3000)
@@ -97,14 +97,17 @@
$template->render($taxform);
}
-sub generate_report
-{
+sub generate_report {
+
+
my ($request) = @_;
- if ($request->{meta_number})
- {
- my @call_args = ($request->{'tax_form_id'}, $request->{begin_month}.' '.$request->{begin_day}.' '.$request->{begin_year}, $request->{end_month}.' '.$request->{end_day}.' '.$request->{end_year}, $request->{meta_number});
- my @results = $request->call_procedure(procname => 'tax_form_details_report', args => ..hidden.., );
+ if ($request->{meta_number}) {
+ my @call_args = ($request->{'tax_form_id'},
+ $request->{begin_month}.' '.$request->{begin_day}.' '.$request->{begin_year}, $request->{end_month}.' '.$request->{end_day}.' '.$request->{end_year},
+ $request->{meta_number});
+
+ my @results = $request->call_procedure(procname => 'tax_form_details_report', args => ..hidden..);
for my $r (@results){
$r->{acc_sum} = $request->format_amount({amount => $r->{acc_sum}});
$r->{invoice_sum} =
@@ -121,25 +124,27 @@
format => 'HTML'
);
$template->render($request);
- } else {
- my @call_args = ($request->{'tax_form_id'}, $request->{begin_month}.' '.$request->{begin_day}.' '.$request->{begin_year}, $request->{end_month}.' '.$request->{end_day}.' '.$request->{end_year});
- my @results = $request->call_procedure(procname => 'tax_form_summary_report', args => ..hidden.., );
- for my $r (@results){
- $r->{acc_sum} = $request->format_amount({amount => $r->{acc_sum}});
- $r->{invoice_sum} =
- $request->format_amount({amount => $r->{invoice_sum}});
- $r->{total_sum} = $request->format_amount({amount => $r->{total_sum}});
- }
- $request->{results} = ..hidden..;
-
- my $template = LedgerSMB::Template->new(
- user => $request->{_user},
- locale => $request->{_locale},
- path => 'UI',
- template => 'taxform/summary_report',
- format => 'HTML'
- );
- $template->render($request);
+ }
+ else {
+
+ my @call_args = ($request->{'tax_form_id'}, $request->{begin_month}.' '.$request->{begin_day}.' '.$request->{begin_year}, $request->{end_month}.' '.$request->{end_day}.' '.$request->{end_year});
+ my @results = $request->call_procedure(procname => 'tax_form_summary_report', args => ..hidden..);
+ for my $r (@results){
+ $r->{acc_sum} = $request->format_amount({amount => $r->{acc_sum}});
+ $r->{invoice_sum} =
+ $request->format_amount({amount => $r->{invoice_sum}});
+ $r->{total_sum} = $request->format_amount({amount => $r->{total_sum}});
+ }
+ $request->{results} = ..hidden..;
+
+ my $template = LedgerSMB::Template->new(
+ user => $request->{_user},
+ locale => $request->{_locale},
+ path => 'UI',
+ template => 'taxform/summary_report',
+ format => 'HTML'
+ );
+ $template->render($request);
}
}
Modified: trunk/sql/Pg-database.sql
===================================================================
--- trunk/sql/Pg-database.sql 2010-05-05 18:09:08 UTC (rev 2999)
+++ trunk/sql/Pg-database.sql 2010-05-05 18:48:24 UTC (rev 3000)
@@ -939,8 +939,7 @@
emd.enddate,
eba.bic,
eba.iban,
- ein.note as
- invoice_notes
+ ein.note as invoice_notes
FROM entity_credit_account emd
LEFT join entity_bank_account eba on emd.entity_id = eba.entity_id
left join entity_note ein on ein.ref_key = emd.entity_id
Modified: trunk/sql/modules/1099_reports.sql
===================================================================
--- trunk/sql/modules/1099_reports.sql 2010-05-05 18:09:08 UTC (rev 2999)
+++ trunk/sql/modules/1099_reports.sql 2010-05-05 18:48:24 UTC (rev 3000)
@@ -1,6 +1,25 @@
-CREATE TYPE tax_form_report_item AS (legal_name text, entity_id integer, entity_class integer, control_code text, meta_number character varying(32), acc_sum numeric, invoice_sum numeric, total_sum numeric);
-CREATE TYPE tax_form_report_detail_item AS (legal_name text, entity_id integer, entity_class integer, control_code text, meta_number character varying(32), acc_sum numeric, invoice_sum numeric, total_sum numeric, invnumber text, duedate text);
+CREATE TYPE tax_form_report_item AS (
+ legal_name text,
+ entity_id integer,
+ entity_class integer,
+ control_code text,
+ meta_number character varying(32),
+ acc_sum numeric,
+ invoice_sum numeric,
+ total_sum numeric);
+CREATE TYPE tax_form_report_detail_item AS (
+ legal_name text,
+ entity_id integer,
+ entity_class integer,
+ control_code text,
+ meta_number character varying(32),
+ acc_sum numeric,
+ invoice_sum numeric,
+ total_sum numeric,
+ invnumber text,
+ duedate text);
+
CREATE OR REPLACE FUNCTION tax_form__list_all()
RETURNS SETOF country_tax_form as
$$
@@ -92,7 +111,7 @@
JOIN country_tax_form ON (entity_credit_account.taxform_id = country_tax_form.id)
WHERE country_tax_form.id = in_tax_form_id AND meta_number = in_meta_number
AND transdate BETWEEN in_begin AND in_end
- GROUP BY legal_name, meta_number, company.entity_id, entity_credit_account.entity_class, entity.control_code, gl.invnumber, gl.duedate
+ GROUP BY legal_name, meta_number, company.entity_id, entity_credit_account.entity_class, entity.control_code, gl.invnumber, gl.duedate, gl.id
LOOP
RETURN NEXT out_row;
END LOOP;
Modified: trunk/sql/modules/Company.sql
===================================================================
--- trunk/sql/modules/Company.sql 2010-05-05 18:09:08 UTC (rev 2999)
+++ trunk/sql/modules/Company.sql 2010-05-05 18:48:24 UTC (rev 3000)
@@ -743,29 +743,72 @@
DECLARE
l_row location;
l_id INT;
+ l_orig_id INT;
BEGIN
+ PERFORM location_id
+ FROM eca_to_location
+ WHERE credit_id = in_credit_id
+ AND location_class = in_location_class
+ AND location_id = in_location_id;
+
+ IF FOUND THEN
+ SELECT location_save(
+ in_location_id,
+ in_line_one,
+ in_line_two,
+ in_line_three,
+ in_city,
+ in_state,
+ in_mail_code,
+ in_country_code
+ )
+ INTO l_id;
+ ELSE
+ SELECT location_save(
+ NULL,
+ in_line_one,
+ in_line_two,
+ in_line_three,
+ in_city,
+ in_state,
+ in_mail_code,
+ in_country_code
+ )
+ INTO l_id;
+ INSERT INTO eca_to_location
+ (credit_id, location_class, location_id)
+ VALUES (in_credit_id, in_location_class, l_id);
+
+ END IF;
- DELETE FROM eca_to_location
- WHERE credit_id = in_credit_id
- AND location_class = in_location_class
- AND location_id = in_location_id;
-
- -- don't pass the in_location_id through because that is not safe.
- SELECT location_save(NULL, in_line_one, in_line_two, in_line_three,
- in_city,
- in_state, in_mail_code, in_country_code)
- INTO l_id;
-
- INSERT INTO eca_to_location
- (credit_id, location_class, location_id)
- VALUES (in_credit_id, in_location_class, l_id);
-
RETURN l_id;
END;
$$ language 'plpgsql';
+CREATE OR REPLACE FUNCTION eca__get_location(
+ in_credit_id int,
+ in_class text
+) RETURNS location_result AS
+$$
+ SELECT l.id,
+ l.line_one,
+ l.line_two,
+ l.line_three,
+ l.city,
+ l.state,
+ l.mail_code,
+ c.name,
+ lc.class
+ FROM location l
+ JOIN eca_to_location ctl ON (ctl.location_id = l.id)
+ JOIN location_class lc ON (ctl.location_class = lc.id)
+ JOIN country c ON (c.id = l.country_id)
+ WHERE ctl.credit_id = $1
+ AND lc.class = $2;
+$$ LANGUAGE SQL;
+
CREATE OR REPLACE FUNCTION eca__list_locations(in_credit_id int)
RETURNS SETOF location_result AS
$$
@@ -808,16 +851,40 @@
$$
DECLARE out_id int;
BEGIN
- DELETE FROM eca_to_contact
- WHERE credit_id = in_credit_id
- AND contact = in_old_contact
- AND contact_class_id = in_old_contact_class;
-
- INSERT INTO eca_to_contact(credit_id, contact_class_id,
- description, contact)
- VALUES (in_credit_id, in_contact_class, in_description, in_contact);
+ PERFORM *
+ FROM eca_to_contact
+ WHERE credit_id = in_credit_id
+ AND contact_class_id = in_old_contact_class
+ AND contact = in_old_contact;
+
+ IF FOUND THEN
+ UPDATE eca_to_contact
+ SET contact = in_contact,
+ description = in_description,
+ contact_class_id = in_contact_class
+ WHERE credit_id = in_credit_id
+ AND contact_class_id = in_old_contact_class
+ AND contact = in_old_contact;
+ ELSE
+ INSERT INTO eca_to_contact(credit_id, contact_class_id,
+ description, contact)
+ VALUES (in_credit_id, in_contact_class, in_description, in_contact);
+
+ END IF;
+
RETURN 1;
END;
$$ LANGUAGE PLPGSQL;
+CREATE OR REPLACE FUNCTION company__get_all_accounts (
+ in_entity_id int,
+ in_entity_class int
+) RETURNS SETOF entity_credit_account AS $body$
+
+ SELECT *
+ FROM entity_credit_account
+ WHERE entity_id = $1
+ AND entity_class = $2;
+
+$body$ language SQL;
Modified: trunk/sql/modules/EndOfYear.sql
===================================================================
--- trunk/sql/modules/EndOfYear.sql 2010-05-05 18:09:08 UTC (rev 2999)
+++ trunk/sql/modules/EndOfYear.sql 2010-05-05 18:48:24 UTC (rev 3000)
@@ -160,7 +160,8 @@
CREATE OR REPLACE FUNCTION eoy_earnings_accounts() RETURNS setof account AS
$$
-SELECT * FROM account
-WHERE category = 'Q'
-ORDER BY accno;
+ SELECT *
+ FROM account
+ WHERE category = 'Q'
+ ORDER BY accno;
$$ language sql;
Modified: trunk/sql/modules/Entity.sql
===================================================================
--- trunk/sql/modules/Entity.sql 2010-05-05 18:09:08 UTC (rev 2999)
+++ trunk/sql/modules/Entity.sql 2010-05-05 18:48:24 UTC (rev 3000)
@@ -12,7 +12,6 @@
select * into e from entity where id = in_entity_id;
-
update
entity
SET
Modified: trunk/sql/modules/Roles.sql
===================================================================
--- trunk/sql/modules/Roles.sql 2010-05-05 18:09:08 UTC (rev 2999)
+++ trunk/sql/modules/Roles.sql 2010-05-05 18:48:24 UTC (rev 3000)
@@ -82,6 +82,7 @@
GRANT DELETE ON eca_to_location TO "lsmb_<?lsmb dbname ?>__contact_create";
GRANT INSERT ON eca_to_contact TO "lsmb_<?lsmb dbname ?>__contact_create";
GRANT DELETE ON eca_to_contact TO "lsmb_<?lsmb dbname ?>__contact_create";
+GRANT UPDATE ON eca_to_contact TO "lsmb_<?lsmb dbname ?>__contact_create";
GRANT INSERT ON eca_note TO "lsmb_<?lsmb dbname ?>__contact_create";
@@ -1511,3 +1512,5 @@
GRANT EXECUTE ON FUNCTION batch_delete(int)
TO "lsmb_<?lsmb dbname ?>__voucher_delete";
+
+
Modified: trunk/sql/modules/test/System.sql
===================================================================
--- trunk/sql/modules/test/System.sql 2010-05-05 18:09:08 UTC (rev 2999)
+++ trunk/sql/modules/test/System.sql 2010-05-05 18:48:24 UTC (rev 3000)
@@ -22,6 +22,7 @@
insert into test_exempt_funcs values ('crosstab');
insert into test_exempt_funcs values ('concat_colon');
insert into test_exempt_funcs values ('to_args');
+insert into test_exempt_funcs values ('table_log_restore_table');
create table test_exempt_tables (tablename text, reason text);
insert into test_exempt_tables values ('note', 'abstract table, no data');
Added: trunk/sql/modules/test/Taxform.sql
===================================================================
--- trunk/sql/modules/test/Taxform.sql (rev 0)
+++ trunk/sql/modules/test/Taxform.sql 2010-05-05 18:48:24 UTC (rev 3000)
@@ -0,0 +1,238 @@
+/*
+
+This tests the new taxform functions in 1099_reports.sql
+
+Per discussion with Chris, test cases function in the form of:
+
+AP, acc_trans, invoice (on some items), ac_taxform (some items), invoice_taxform (some items)
+
+Invoice tests:
+* Create a new account, for testing
+* Insert a record into transactions
+* Insert a record into AP
+* Insert a record into transactions
+* Insert a record into acc_trans
+* Associate acc_trans with 2nd transaction
+
+
+*/
+
+BEGIN;
+
+\i Base.sql
+
+/* First, we do the invoice testing */
+
+INSERT INTO account_heading(id, accno ) VALUES (-255, '-billion');
+INSERT INTO account (id, accno, category, heading ) VALUES (-255, '-billion', 'T', -255);
+
+-- New account is created.
+
+
+-- Set up a tax form.
+
+INSERT INTO country_tax_form (country_id, form_name, id) VALUES (232, 'Testing Form', -511);
+
+-- Set up an ECA, for AP.
+
+
+INSERT INTO entity_credit_account (id, entity_id, entity_class, meta_number, taxform_id, ar_ap_account_id) VALUES (-255, -100, 1, 'Test account', -511, -255);
+
+INSERT INTO company (id, entity_id, legal_name) VALUES (-1024, -100, 'Testing Tax Form');
+
+-- Set up the Transaction
+--INSERT INTO transactions (id) VALUES (-255);
+
+INSERT INTO ap (id, amount, approved, entity_credit_account, curr) VALUES (-255, 5000, 't'::bool, -255, 'USD');
+
+INSERT INTO acc_trans (trans_id, chart_id, amount, approved, entry_id) VALUES (-255, -255, 5000, 't'::bool, -1000);
+
+-- Set up the second transaction
+
+INSERT INTO ap (id, amount, approved, entity_credit_account, curr) VALUES (-256, -1000, 't'::bool, -255, 'USD');
+INSERT INTO acc_trans (trans_id, chart_id, amount, approved, entry_id) VALUES (-256, -255, -1000, 't'::bool, -1001);
+
+INSERT INTO ap (id, amount, approved, entity_credit_account, curr) VALUES (-257, -1500, 't'::bool, -255, 'USD');
+INSERT INTO acc_trans (trans_id, chart_id, amount, approved, entry_id) VALUES (-257, -255, -1500, 't'::bool, -1002);
+
+INSERT INTO ap (id, amount, approved, entity_credit_account, curr) VALUES (-258, -2500, 't'::bool, -255, 'USD');
+INSERT INTO acc_trans (trans_id, chart_id, amount, approved, entry_id) VALUES (-258, -255, -2500, 't'::bool, -1003);
+
+
+-- Now we set up the invoice entries themselves.
+
+
+INSERT INTO invoice (id, trans_id, sellprice, qty) VALUES (-1000, -256, 250, 4);
+INSERT INTO invoice (id, trans_id, sellprice, qty) VALUES (-1001, -257, 750, 2);
+INSERT INTO invoice (id, trans_id, sellprice, qty) VALUES (-1002, -258, 500, 5);
+
+-- And finally, the tax_form references
+
+INSERT INTO invoice_tax_form (invoice_id, reportable) VALUES (-1000, TRUE);
+INSERT INTO invoice_tax_form (invoice_id, reportable) VALUES (-1001, TRUE);
+INSERT INTO invoice_tax_form (invoice_id, reportable) VALUES (-1002, TRUE);
+
+--
+-- Finally, we test if the entries are showing up
+--
+
+
+-- There should be three entries.
+
+INSERT INTO test_result(test_name, success)
+VALUES ('3 Reportable Invoices, sum of 5000', (
+ SELECT
+ CASE WHEN invoice_sum <> 5000 THEN
+ FALSE
+ ELSE
+ TRUE
+ END as success
+ FROM tax_form_summary_report(-511, (now()::date- '1 day'::interval)::date, now()::date)
+));
+
+--select * from tax_form_details_report(-511, (now() - '1 day'::interval)::date, now()::date, 'Test account');
+
+-- Test reportable-only
+
+UPDATE invoice_tax_form SET reportable = FALSE where invoice_id = -1001;
+
+
+INSERT INTO test_result(test_name, success)
+VALUES ('2 Reportable invoices, 1 disabled, sum of 1000', (
+ SELECT
+ CASE WHEN total_sum <> 3500 THEN
+ FALSE
+ ELSE
+ TRUE
+ END as success
+ FROM tax_form_summary_report(-511, (now()::date- '1 day'::interval)::date, now()::date)
+));
+
+-- Clean up all the invoices and test the AP form instead.
+
+DELETE FROM invoice_tax_form WHERE invoice_id < 0 AND reportable is TRUE;
+DELETE FROM invoice WHERE id < 0 AND id NOT IN (select invoice_id from invoice_tax_form);
+
+
+-- AC tax form stuff
+
+
+INSERT INTO ac_tax_form (entry_id, reportable) VALUES (-1001, 't'::bool);
+INSERT INTO ac_tax_form (entry_id, reportable) VALUES (-1002, 't'::bool);
+INSERT INTO ac_tax_form (entry_id, reportable) VALUES (-1003, 't'::bool);
+
+--select * from tax_form_details_report(-511, (now() - '1 day'::interval)::date, now()::date, 'Test account');
+
+-- And now, test the AC tax form
+
+INSERT INTO test_result(test_name, success)
+VALUES ('3 Reportable AC tax forms', (
+ SELECT
+ CASE WHEN total_sum <> -5000 THEN
+ FALSE
+ ELSE
+ TRUE
+ END as success
+ FROM tax_form_summary_report(-511, (now()::date- '1 day'::interval)::date, now()::date)
+));
+
+UPDATE ac_tax_form SET reportable = FALSE where entry_id = -1002;
+
+
+INSERT INTO test_result(test_name, success)
+VALUES ('Detail test, 2 records', (
+ SELECT
+ CASE WHEN count(*) <> 2 THEN
+ FALSE
+ ELSE
+ TRUE
+ END as success
+ FROM tax_form_details_report(-511, (now() - '1 day'::interval)::date, now()::date, 'Test account')
+));
+
+INSERT INTO test_result(test_name, success)
+VALUES ('Detail test, 2 records sum of acc_sum is -3500 ', (
+ SELECT
+ CASE WHEN sum(acc_sum) <> -3500 THEN
+ FALSE
+ ELSE
+ TRUE
+ END as success
+ FROM tax_form_details_report(-511, (now() - '1 day'::interval)::date, now()::date, 'Test account')
+));
+
+
+
+INSERT INTO test_result(test_name, success)
+VALUES ('2 Reportable invoices, 1 disabled', (
+ SELECT
+ CASE WHEN total_sum <> -3500 THEN
+ FALSE
+ ELSE
+ TRUE
+ END as success
+ FROM tax_form_summary_report(-511, (now()::date- '1 day'::interval)::date, now()::date)
+));
+
+UPDATE invoice_tax_form SET reportable = TRUE;
+
+
+INSERT INTO test_result(test_name, success)
+VALUES ('2 Reportable invoices, 1 disabled, 1 invoice', (
+ SELECT
+ CASE WHEN total_sum <> -2000 THEN
+ FALSE
+ ELSE
+ TRUE
+ END as success
+ FROM tax_form_summary_report(-511, (now()::date- '1 day'::interval)::date, now()::date)
+));
+
+INSERT INTO test_result(test_name, success)
+VALUES ('2 Reportable invoices, 1 disabled, 1 invoice, acc_sum is -3500', (
+ SELECT
+ CASE WHEN acc_sum <> -3500 THEN
+ FALSE
+ ELSE
+ TRUE
+ END as success
+ FROM tax_form_summary_report(-511, (now()::date- '1 day'::interval)::date, now()::date)
+));
+
+INSERT INTO test_result(test_name, success)
+VALUES ('2 Reportable invoices, 1 disabled, 1 invoice, invoice_total is 1500', (
+ SELECT
+ CASE WHEN invoice_sum <> 1500 THEN
+ FALSE
+ ELSE
+ TRUE
+ END as success
+ FROM tax_form_summary_report(-511, (now()::date- '1 day'::interval)::date, now()::date)
+));
+
+
+-- Now, do the detail testing.
+-- At this point, there ought to be 3 records.
+
+
+INSERT INTO test_result(test_name, success)
+VALUES ('Detail test, 3 records', (
+ SELECT
+ CASE WHEN count(*) <> 3 THEN
+ FALSE
+ ELSE
+ TRUE
+ END as success
+ FROM tax_form_details_report(-511, (now() - '1 day'::interval)::date, now()::date, 'Test account')
+));
+
+
+
+SELECT * FROM test_result;
+
+SELECT (select count(*) from test_result where success is true)
+|| ' tests passed and '
+|| (select count(*) from test_result where success is not true)
+|| ' failed' as message;
+
+ROLLBACK;
\ No newline at end of file
Modified: trunk/t/43-dbtest.t
===================================================================
--- trunk/t/43-dbtest.t 2010-05-05 18:09:08 UTC (rev 2999)
+++ trunk/t/43-dbtest.t 2010-05-05 18:48:24 UTC (rev 3000)
@@ -5,7 +5,7 @@
plan skip_all => 'Skipping all. Told not to test db.';
}
else {
- plan tests => 100;
+ plan tests => 110;
if (defined $ENV{LSMB_NEW_DB}){
$ENV{PGDATABASE} = $ENV{LSMB_NEW_DB};
}
@@ -15,7 +15,7 @@
}
my @testscripts = qw(Account Reconciliation Business_type Company Draft Payment
- Session Voucher System);
+ Session Voucher System Taxform);
chdir 'sql/modules/test/';
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.