From d4f3ec54f158e60565f7eccac83c88bf1cb934b6 Mon Sep 17 00:00:00 2001 From: einhverfr Date: Tue, 27 Nov 2007 02:27:48 +0000 Subject: AR/AP Breakage Fixed git-svn-id: https://ledger-smb.svn.sourceforge.net/svnroot/ledger-smb/trunk@1909 4979c152-3d1c-0410-bac9-87ea11338e46 --- LedgerSMB.pm | 9 +++++++ LedgerSMB/AA.pm | 2 +- LedgerSMB/DBObject.pm | 12 --------- LedgerSMB/DBObject/Company.pm | 6 +++++ LedgerSMB/Form.pm | 8 +++--- UI/Contact/contact.html | 63 ++++++++++++++++++++++++++++++++----------- scripts/customer.pl | 8 ++++++ scripts/employee.pl | 8 ++++++ scripts/vendor.pl | 9 +++++++ sql/Pg-database.sql | 8 +++++- sql/modules/Company.sql | 32 ++++++++++++++++++---- sql/modules/Roles.sql | 4 +++ 12 files changed, 131 insertions(+), 38 deletions(-) diff --git a/LedgerSMB.pm b/LedgerSMB.pm index b4d6c360..61e655ec 100755 --- a/LedgerSMB.pm +++ b/LedgerSMB.pm @@ -150,6 +150,15 @@ sub new { $self->merge($params); + # Adding this so that empty values are stored in the db as NULL's. If + # stored procedures want to handle them differently, they must opt to do so. + # -- CT + for (keys %$self){ + if ($self->{$_} eq ''){ + $self->{$_} = undef; + } + } + if ($self->is_run_mode('cgi', 'mod_perl')) { $ENV{HTTP_COOKIE} =~ s/;\s*/;/g; my @cookies = split /;/, $ENV{HTTP_COOKIE}; diff --git a/LedgerSMB/AA.pm b/LedgerSMB/AA.pm index c539a34a..d9c67181 100644 --- a/LedgerSMB/AA.pm +++ b/LedgerSMB/AA.pm @@ -908,7 +908,7 @@ sub transactions { if ( $myconfig->{role} eq 'user' ) { my $login = $dbh->quote( $form->{login} ); - $where .= " AND e.login = $login"; + $where .= " AND e.entity_id = (select entity_id from users where username = $login"; } } diff --git a/LedgerSMB/DBObject.pm b/LedgerSMB/DBObject.pm index 3451d823..be6ea7ef 100644 --- a/LedgerSMB/DBObject.pm +++ b/LedgerSMB/DBObject.pm @@ -45,18 +45,6 @@ use base qw(LedgerSMB); use strict; use warnings; -our $AUTOLOAD; - -sub AUTOLOAD { - my ($self) = shift; - my $type = Scalar::Util::blessed $self; - $type =~ m/::(.*?)$/; - $type = lc $1; - $self->exec_method( funcname => "$type" . "_" . $AUTOLOAD, args => \@_); -} - -sub DESTROY {} - sub __validate__ {} sub new { diff --git a/LedgerSMB/DBObject/Company.pm b/LedgerSMB/DBObject/Company.pm index 5d7d760e..ed94b015 100644 --- a/LedgerSMB/DBObject/Company.pm +++ b/LedgerSMB/DBObject/Company.pm @@ -52,6 +52,12 @@ sub save_bank_account { $self->{dbh}->commit; } +sub save_notes { + my $self = shift @_; + $self->exec_method(funcname => 'entity__save_notes'); + $self->{dbh}->commit; +} + sub get { my $self = shift @_; diff --git a/LedgerSMB/Form.pm b/LedgerSMB/Form.pm index 9e7c7748..7c3a6d65 100644 --- a/LedgerSMB/Form.pm +++ b/LedgerSMB/Form.pm @@ -1616,8 +1616,8 @@ sub get_employee { my $query = qq| SELECT name, id FROM entity WHERE id IN (select entity_id - FROM employee - WHERE login = ?)|; + FROM users + WHERE username = ?)|; my $sth = $self->{dbh}->prepare($query); $sth->execute($login); @@ -1721,9 +1721,9 @@ sub all_vc { my $sth; if ($vc eq 'customer'){ - $self->{vc_class} = 2; - } else { $self->{vc_class} = 1; + } else { + $self->{vc_class} = 2; $vc = 'vendor'; } my $query = qq|SELECT count(*) FROM entity_credit_account where entity_class = ?|; diff --git a/UI/Contact/contact.html b/UI/Contact/contact.html index f2d14531..0f3d6af5 100644 --- a/UI/Contact/contact.html +++ b/UI/Contact/contact.html @@ -17,23 +17,29 @@ --> + +
@@ -60,8 +66,6 @@ size = "20" } ?>
-
+
@@ -469,6 +474,34 @@ text = text('Save') } ?>
+ + +
+
+ +
+
+
+ +
+ +
+
+ + +
diff --git a/scripts/customer.pl b/scripts/customer.pl index cf1f734e..ab9a6919 100644 --- a/scripts/customer.pl +++ b/scripts/customer.pl @@ -202,4 +202,12 @@ sub save_bank_account { _render_main_screen($customer); } +sub save_notes { + my ($request) = @_; + my $customer = LedgerSMB::DBObject::Customer->new({base => $request}); + $customer->save_notes(); + $customer->get(); + _render_main_screen($customer); +} + 1; diff --git a/scripts/employee.pl b/scripts/employee.pl index 61ff978a..b265dba5 100644 --- a/scripts/employee.pl +++ b/scripts/employee.pl @@ -202,4 +202,12 @@ sub save_bank_account { _render_main_screen($employee); } +sub save_notes { + my ($request) = @_; + my $employee = LedgerSMB::DBObject::Employee->new({base => $request}); + $employee->save_notes(); + $employee->get(); + _render_main_screen($employee); +} + 1; diff --git a/scripts/vendor.pl b/scripts/vendor.pl index a8a6aad0..6fa2cf77 100644 --- a/scripts/vendor.pl +++ b/scripts/vendor.pl @@ -194,6 +194,7 @@ sub save_contact { _render_main_screen($vendor ); } + sub save_bank_account { my ($request) = @_; my $vendor = LedgerSMB::DBObject::Vendor->new({base => $request}); @@ -202,4 +203,12 @@ sub save_bank_account { _render_main_screen($vendor ); } +sub save_notes { + my ($request) = @_; + my $vendor = LedgerSMB::DBObject::Vendor->new({base => $request}); + $vendor->save_notes(); + $vendor->get(); + _render_main_screen($vendor ); +} + 1; diff --git a/sql/Pg-database.sql b/sql/Pg-database.sql index 17f62313..ce443302 100644 --- a/sql/Pg-database.sql +++ b/sql/Pg-database.sql @@ -431,6 +431,12 @@ CREATE TABLE entity_credit_account ( -- ssn, iban and bic are from entity_credit_account -- -- The view below is broken. Disabling for now. +CREATE VIEW employee AS + SELECT s.salutation, p.first_name, p.last_name, ee.person_id, ee.entity_id, ee.startdate, ee.enddate, ee."role", ee.ssn, ee.sales, ee.manager_id, ee.employeenumber, ee.dob + FROM person p + JOIN entity_employee ee USING (entity_id) + JOIN salutation s ON p.salutation_id = s.id; + /* create view employee as SELECT @@ -535,7 +541,7 @@ ALTER TABLE company ADD COLUMN sic_code varchar; --- COMMENT ON TABLE employee IS $$ Is a metadata table specific to employees $$; +-- COMMENT ON TABLE employee IS $$ Is a metadata table specific to employee $$; CREATE TABLE parts ( id serial PRIMARY KEY, diff --git a/sql/modules/Company.sql b/sql/modules/Company.sql index 3973ff2b..6b48ddf7 100644 --- a/sql/modules/Company.sql +++ b/sql/modules/Company.sql @@ -1,4 +1,19 @@ BEGIN; + +CREATE OR REPLACE FUNCTION entity__save_notes(in_entity_id int, in_note text) +RETURNS INT AS +$$ +DECLARE out_id int; +BEGIN + -- TODO, change this to create vector too + INSERT INTO entity_note (ref_key, note_class, entity_id, note, vector) + VALUES (in_entity_id, 1, in_entity_id, in_note, ''); + + SELECT currval('note_id_seq') INTO out_id; + RETURN out_id; +END; +$$ LANGUAGE PLPGSQL; + CREATE OR REPLACE FUNCTION entity_list_contact_class() RETURNS SETOF contact_class AS $$ @@ -35,11 +50,12 @@ COMMENT ON TYPE entity_credit_search_return IS $$ This may change in 1.4 and should not be relied upon too much $$; CREATE OR REPLACE FUNCTION entity__retrieve_credit -(in_entity_id int, in_entity_cass int) +(in_entity_id int, in_entity_class int) RETURNS entity_credit_search_return AS $$ DECLARE out_row customer_search_return; BEGIN + SELECT c.legal_name, c.id, e.id, ec.entity_class, ec.discount, ec.taxincluded, ec.creditlimit, ec.terms, ec.meta_number, ec.business_id, ec.language_code, ec.pricegroup_id, @@ -49,12 +65,15 @@ BEGIN JOIN entity e ON (c.entity_id = e.id) JOIN entity_credit_account ec ON (c.entity_id = ec.entity_id) WHERE e.id = in_entity_id - AND ec.entity_class = in_entity_class; + AND ec.entity_class = CASE WHEN in_entity_class = 3 THEN 2 + ELSE in_entity_class END; RETURN out_row; END; $$ LANGUAGE PLPGSQL; +CREATE company + CREATE OR REPLACE FUNCTION entity_credit_save ( in_id int, in_entity_class int, @@ -89,6 +108,9 @@ CREATE OR REPLACE FUNCTION entity_credit_save ( INSERT INTO company ( entity_id, legal_name, tax_id ) VALUES ( new_entity_id, in_name, in_tax_id ); + IF in_entity_class NOT IN (1, 2) THEN + RETURN new_entity_id; + END IF; INSERT INTO entity_credit_account ( entity_id, @@ -126,7 +148,7 @@ CREATE OR REPLACE FUNCTION entity_credit_save ( ); -- entity note class insert into entity_note (note_class, note, ref_key, vector) VALUES ( - 1, in_notes, new_entity_id, ''); + 1, in_notes, new_entity_id, to_tsvector(in_notes)); return new_entity_id; @@ -251,12 +273,12 @@ CREATE TYPE entity_note_list AS ( ); CREATE OR REPLACE FUNCTION company__list_notes(in_entity_id int) -RETURNS SETOF entity_note_list AS +RETURNS SETOF entity_note AS $$ DECLARE out_row record; BEGIN FOR out_row IN - SELECT id, note + SELECT * FROM entity_note WHERE ref_key = in_entity_id LOOP diff --git a/sql/modules/Roles.sql b/sql/modules/Roles.sql index aace8a8c..1425ff87 100644 --- a/sql/modules/Roles.sql +++ b/sql/modules/Roles.sql @@ -1380,3 +1380,7 @@ GRANT SELECT ON custom_table_catalog TO PUBLIC; GRANT SELECT ON custom_field_catalog TO PUBLIC; grant select on menu_node, menu_attribute, menu_acl to public; GRANT select on chart, gifi, country to public; + grant select on employee to public; + GRANT SELECT ON parts, partsgroup TO public; + GRANT SELECT ON language TO public; +GRANT SELECT ON business, exchangerate, shipto, tax TO public; -- cgit v1.2.3