summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xLedgerSMB.pm9
-rw-r--r--LedgerSMB/AA.pm2
-rw-r--r--LedgerSMB/DBObject.pm12
-rw-r--r--LedgerSMB/DBObject/Company.pm6
-rw-r--r--LedgerSMB/Form.pm8
-rw-r--r--UI/Contact/contact.html63
-rw-r--r--scripts/customer.pl8
-rw-r--r--scripts/employee.pl8
-rw-r--r--scripts/vendor.pl9
-rw-r--r--sql/Pg-database.sql8
-rw-r--r--sql/modules/Company.sql32
-rw-r--r--sql/modules/Roles.sql4
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 @@
<?lsmb text("Edit Employee") ?>
-->
<ul class="navigation">
+ <?lsmb IF entity_class == 3 ?>
+ <li><a href="#hr_div"><?lsmb text('HR') ?></a></li>
+ <?lsmb ELSE ?>
<li><a href="#customer_div"><?lsmb text('Account') ?></a></li>
+ <?lsmb END ?>
<?lsmb IF entity_id ?>
<li><a href="#location_div"><?lsmb text('Addresses') ?></a></li>
<li><a href="#contact_div"><?lsmb text('Contact Info') ?></a></li>
<li><a href="#bank_div"><?lsmb text('Bank Accounts') ?></a></li>
- <!-- Commented out as not yet implemented -CT
<li><a href="#notes_div"><?lsmb text('Notes') ?></a></li>
+ <!-- Commented out as not yet implemented -CT
<li><a href="#history_div"><?lsmb text('History') ?></a></li>
+ <li><a href="#user_div"><?lsmb text('User') ?></a></li>
-->
<?lsmb END ?>
</ul>
</div>
+<?lsmb IF entity_class == 3 ?>
+<?lsmb ELSE ?>
<div class="container" id="customer_div">
<?lsmb SWITCH entity_class
?><?lsmb CASE 1 ?><?lsmb entity_classname = "Vendor"
?><?lsmb CASE 2 ?><?lsmb entity_classname = "Customer"
- ?><?lsmb CASE 3 ?><?lsmb entity_classname = "Employee"
?><?lsmb END ?>
<div class="listtop"><strong><?lsmb text("$operation $entity_classname") ?></strong></div>
<?lsmb FOREACH n = notes ?>
@@ -60,8 +66,6 @@
size = "20"
} ?><br/>
<table>
- <!-- TODO: Create another tab for order history, and another one
- for notes -->
<tr>
<td>
<?lsmb PROCESS input element_data = {
@@ -182,28 +186,28 @@
class="submit"
type="submit"
name="action"
- value="ap_transaction"
+ value="add_transaction"
accesskey="A"
- title="AP Transaction [Alt-A]"
- text = text('AP Transaction')
+ title="Transaction [Alt-A]"
+ text = (entity_class == 1) ? text('AP Transaction') : text('AR Transaction')
} ?>
<?lsmb PROCESS button element_data = {
class="submit"
type="submit"
name="action"
- value="customer_invoice"
+ value="add_invoice"
accesskey="I"
- title="customer Invoice [Alt-I]"
- text = text('Customer Invoice')
+ title="Invoice [Alt-I]"
+ text = (entity_class == 1) ? text('Vendor Invoice') : text('Customer Invoice')
} ?>
<?lsmb PROCESS button element_data = {
class="submit"
type="submit"
name="action"
- value="purchase_order"
+ value="add_order"
accesskey="O"
- title="Purchase Order [Alt-O]"
- text = text('Purchase Order')
+ title="Order [Alt-O]"
+ text = (entity_class == 1) ? text('Purchase Order') : text('Sales Order')
} ?>
<?lsmb PROCESS button element_data = {
class="submit"
@@ -211,8 +215,8 @@
name="action"
value="rfq"
accesskey="Q"
- title="RFQ [Alt-Q]"
- text = text('RFQ')
+ title="Quotation [Alt-Q]"
+ text = (entity_class == 1) ? text('RFQ') : text('Quotation')
} ?>
<?lsmb PROCESS button element_data = {
class="submit"
@@ -225,6 +229,7 @@
} ?>
</form>
</div>
+<?lsmb END ?>
<?lsmb IF entity_id ?>
<div id="location_div" class="container">
<div class="listtop"><?lsmb text('Locations') ?></div>
@@ -469,6 +474,34 @@
text = text('Save')
} ?>
</div>
+</form>
+</div>
+<div id="notes_div">
+<div class="listtop"><?lsmb text('Notes') ?></div>
+<?lsmb FOREACH n = notes ?>
+<div class="note">
+<div class="timestamp"><?lsmb text('Entered at: [_1]', n.created) ?></div>
+<div class="contents"><?lsmb n.note ?></div>
+<?lsmb END ?>
+<form action="<?lsmb script ?>" method="post">
+ <?lsmb PROCESS input element_data = {
+ type="hidden"
+ name="entity_id"
+ value=entity_id
+ } ?>
+<div class="input"><?lsmb PROCESS textarea element_data = {
+ label = text('Notes:')
+ name = notes
+} ?></div>
+<div class="input">
+<?lsmb PROCESS button element_data = {
+ text = text('Save')
+ class = 'submit'
+ name = 'action'
+ value = 'save_notes'
+} ?>
+
+</form>
</div>
<?lsmb END ?>
</body>
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;