diff options
-rwxr-xr-x | LedgerSMB.pm | 11 | ||||
-rw-r--r-- | LedgerSMB/AM.pm | 6 | ||||
-rw-r--r-- | LedgerSMB/CT.pm | 24 | ||||
-rw-r--r-- | LedgerSMB/Form.pm | 59 | ||||
-rw-r--r-- | LedgerSMB/HR.pm | 18 | ||||
-rw-r--r-- | LedgerSMB/IC.pm | 12 | ||||
-rw-r--r-- | LedgerSMB/IS.pm | 2 | ||||
-rw-r--r-- | LedgerSMB/JC.pm | 4 | ||||
-rw-r--r-- | LedgerSMB/OE.pm | 8 | ||||
-rw-r--r-- | LedgerSMB/PE.pm | 2 | ||||
-rw-r--r-- | LedgerSMB/RP.pm | 4 |
11 files changed, 70 insertions, 80 deletions
diff --git a/LedgerSMB.pm b/LedgerSMB.pm index 9c082693..3dc39447 100755 --- a/LedgerSMB.pm +++ b/LedgerSMB.pm @@ -14,8 +14,9 @@ in database objects (LedgerSMB::DBObject) =item new () -This method creates a new base request instance. In any mode but CLI, it also -validates the session/user credentials. +This method creates a new base request instance. It also validates the +session/user credentials, as appropriate for the run mode. Finally, it sets up +the database connections for the user. =item date_to_number (user => $LedgerSMB::User, date => $string); @@ -205,6 +206,7 @@ sub new { exit; } } + $self->_db_init; $self; @@ -604,7 +606,6 @@ sub error { $self->{msg} = $msg; $self->{format} = "html"; - $self->format_string('msg'); delete $self->{pre}; @@ -628,10 +629,10 @@ sub error { } # Database routines used throughout -sub db_init { +sub _db_init { my $self = shift @_; my %args = @_; - my $myconfig = $args{user}; + my $myconfig = $self->{_user}; my $dbh = DBI->connect( $myconfig->{dbconnect}, $myconfig->{dbuser}, diff --git a/LedgerSMB/AM.pm b/LedgerSMB/AM.pm index 618c4d0b..09de5f6b 100644 --- a/LedgerSMB/AM.pm +++ b/LedgerSMB/AM.pm @@ -1314,7 +1314,7 @@ sub save_preferences { my @queryargs; my $query = qq| SELECT login - FROM employees + FROM employee WHERE login = ?|; @queryargs = ( $form->{login} ); my $sth = $dbh->prepare($query); @@ -1326,7 +1326,7 @@ sub save_preferences { # update name $query = qq| - UPDATE employees + UPDATE employee SET name = ? WHERE login = ?|; @@ -1756,7 +1756,7 @@ sub post_yearend { $query = qq| INSERT INTO gl (reference, employee_id) - VALUES (?, (SELECT id FROM employees + VALUES (?, (SELECT id FROM employee WHERE login = ?))|; $dbh->prepare($query)->execute( $uid, $form->{login} ) diff --git a/LedgerSMB/CT.pm b/LedgerSMB/CT.pm index 4d4b260e..785d2dc3 100644 --- a/LedgerSMB/CT.pm +++ b/LedgerSMB/CT.pm @@ -54,7 +54,7 @@ sub create_links { FROM $form->{db} ct LEFT JOIN business b ON (ct.business_id = b.id) LEFT JOIN shipto s ON (ct.id = s.trans_id) - LEFT JOIN employees e ON (ct.employee_id = e.id) + LEFT JOIN employee e ON (ct.employee_id = e.id) LEFT JOIN pricegroup g ON (g.id = ct.pricegroup_id) LEFT JOIN language l ON (l.code = ct.language_code) WHERE ct.id = ?|; @@ -519,8 +519,8 @@ sub search { l.description AS language, m.name AS manager FROM $form->{db} ct LEFT JOIN business b ON (ct.business_id = b.id) - LEFT JOIN employees e ON (ct.employee_id = e.id) - LEFT JOIN employees m ON (m.id = e.managerid) + LEFT JOIN employee e ON (ct.employee_id = e.id) + LEFT JOIN employee m ON (m.id = e.managerid) LEFT JOIN pricegroup g ON (ct.pricegroup_id = g.id) LEFT JOIN language l ON (l.code = ct.language_code) WHERE $where|; @@ -577,8 +577,8 @@ sub search { FROM $form->{db} ct JOIN $ar a ON (a.$form->{db}_id = ct.id) LEFT JOIN business b ON (ct.business_id = b.id) - LEFT JOIN employees e ON (a.employee_id = e.id) - LEFT JOIN employees m ON (m.id = e.managerid) + LEFT JOIN employee e ON (a.employee_id = e.id) + LEFT JOIN employee m ON (m.id = e.managerid) WHERE $where AND a.invoice = '0' $transwhere @@ -613,8 +613,8 @@ sub search { FROM $form->{db} ct JOIN $ar a ON (a.$form->{db}_id = ct.id) LEFT JOIN business b ON (ct.business_id = b.id) - LEFT JOIN employees e ON (a.employee_id = e.id) - LEFT JOIN employees m ON (m.id = e.managerid) + LEFT JOIN employee e ON (a.employee_id = e.id) + LEFT JOIN employee m ON (m.id = e.managerid) WHERE $where AND a.invoice = '1' $transwhere @@ -645,8 +645,8 @@ sub search { FROM $form->{db} ct JOIN oe o ON (o.$form->{db}_id = ct.id) LEFT JOIN business b ON (ct.business_id = b.id) - LEFT JOIN employees e ON (o.employee_id = e.id) - LEFT JOIN employees m ON (m.id = e.managerid) + LEFT JOIN employee e ON (o.employee_id = e.id) + LEFT JOIN employee m ON (m.id = e.managerid) WHERE $where AND o.quotation = '0' $transwhere @@ -678,8 +678,8 @@ sub search { FROM $form->{db} ct JOIN oe o ON (o.$form->{db}_id = ct.id) LEFT JOIN business b ON (ct.business_id = b.id) - LEFT JOIN employees e ON (o.employee_id = e.id) - LEFT JOIN employees m ON (m.id = e.managerid) + LEFT JOIN employee e ON (o.employee_id = e.id) + LEFT JOIN employee m ON (m.id = e.managerid) WHERE $where AND o.quotation = '1' $transwhere @@ -890,7 +890,7 @@ sub get_history { $invjoin JOIN parts p ON (p.id = i.parts_id) LEFT JOIN project pr ON (pr.id = i.project_id) - LEFT JOIN employees e ON (e.id = a.employee_id) + LEFT JOIN employee e ON (e.id = a.employee_id) WHERE $where ORDER BY $sortorder|; diff --git a/LedgerSMB/Form.pm b/LedgerSMB/Form.pm index 4be02825..823ece35 100644 --- a/LedgerSMB/Form.pm +++ b/LedgerSMB/Form.pm @@ -2322,52 +2322,41 @@ sub create_links { $sth->finish; - for (qw(curr closedto revtrans)) { - $query = qq| - SELECT value FROM defaults - WHERE setting_key = '$_'|; - - $sth = $dbh->prepare($query); - $sth->execute || $self->dberror($query); - - ($val) = $sth->fetchrow_array(); - if ( $_ eq 'curr' ) { - $self->{currencies} = $val; - } - else { - $self->{$_} = $val; - } - $sth->finish; - } - $self->{transdate} = $self->current_date; } else { - for (qw(current_date curr closedto revtrans)) { + if ( !$self->{"$self->{vc}_id"} ) { + $self->lastname_used( $myconfig, $dbh, $vc, $module ); + } + } + for (qw(current_date curr closedto revtrans)) { + if ($_ eq 'closedto'){ + $query = qq| + SELECT value::date FROM defaults + WHERE setting_key = '$_'|; + } elsif ($_ eq 'current_date') { + $query = qq| select $_|; + } else { $query = qq| SELECT value FROM defaults WHERE setting_key = '$_'|; + } - $sth = $dbh->prepare($query); - $sth->execute || $self->dberror($query); + $sth = $dbh->prepare($query); + $sth->execute || $self->dberror($query); - ($val) = $sth->fetchrow_array(); - if ( $_ eq 'curr' ) { - $self->{currencies} = $val; - } - elsif ( $_ eq 'current_date' ) { - $self->{transdate} = $val; - } - else { - $self->{$_} = $val; - } - $sth->finish; + ($val) = $sth->fetchrow_array(); + if ( $_ eq 'curr' ) { + $self->{currencies} = $val; } - - if ( !$self->{"$self->{vc}_id"} ) { - $self->lastname_used( $myconfig, $dbh, $vc, $module ); + else { + $self->{$_} = $val; } + $sth->finish; + } + if (!$self->{id}){ + $self->{transdate} = $self->{current_date}; } $self->all_vc( $myconfig, $vc, $module, $dbh, $self->{transdate}, $job ); diff --git a/LedgerSMB/HR.pm b/LedgerSMB/HR.pm index c9869e15..105a4365 100644 --- a/LedgerSMB/HR.pm +++ b/LedgerSMB/HR.pm @@ -44,7 +44,7 @@ sub get_employee { my $notid = ""; if ( $form->{id} ) { - $query = qq|SELECT e.* FROM employees e WHERE e.id = ?|; + $query = qq|SELECT e.* FROM employee e WHERE e.id = ?|; $sth = $dbh->prepare($query); $sth->execute( $form->{id} ) || $form->dberror( __FILE__ . ':' . __LINE__ . ':' . $query ); @@ -63,7 +63,7 @@ sub get_employee { # get manager $form->{managerid} *= 1; - $sth = $dbh->prepare("SELECT name FROM employees WHERE id = ?"); + $sth = $dbh->prepare("SELECT name FROM employee WHERE id = ?"); $sth->execute( $form->{managerid} ); ( $form->{manager} ) = $sth->fetchrow_array; @@ -79,7 +79,7 @@ sub get_employee { # get managers $query = qq| SELECT id, name - FROM employees + FROM employee WHERE sales = '1' AND role = 'manager' $notid @@ -107,11 +107,11 @@ sub save_employee { my $uid = localtime; $uid .= "$$"; - $query = qq|INSERT INTO employees (name) VALUES ('$uid')|; + $query = qq|INSERT INTO employee (name) VALUES ('$uid')|; $dbh->do($query) || $form->dberror( __FILE__ . ':' . __LINE__ . ':' . $query ); - $query = qq|SELECT id FROM employees WHERE name = '$uid'|; + $query = qq|SELECT id FROM employee WHERE name = '$uid'|; $sth = $dbh->prepare($query); $sth->execute || $form->dberror( __FILE__ . ':' . __LINE__ . ':' . $query ); @@ -129,7 +129,7 @@ sub save_employee { if !$form->{employeenumber}; $query = qq| - UPDATE employees + UPDATE employee SET employeenumber = ?, name = ?, address1 = ?, @@ -180,7 +180,7 @@ sub delete_employee { # delete employee my $query = qq| - DELETE FROM employees + DELETE FROM employee WHERE id = | . $dbh->quote( $form->{id} ); $dbh->do($query) || $form->dberror( __FILE__ . ':' . __LINE__ . ':' . $query ); @@ -232,8 +232,8 @@ sub employees { my $query = qq| SELECT e.*, m.name AS manager - FROM employees e - LEFT JOIN employees m ON (m.id = e.managerid) + FROM employee e + LEFT JOIN employee m ON (m.id = e.managerid) WHERE $where ORDER BY $sortorder|; diff --git a/LedgerSMB/IC.pm b/LedgerSMB/IC.pm index 77736e11..671d7e35 100644 --- a/LedgerSMB/IC.pm +++ b/LedgerSMB/IC.pm @@ -1215,7 +1215,7 @@ sub all_parts { ON (a.vendor_id = ct.id) LEFT JOIN partsgroup pg ON (p.partsgroup_id = pg.id) - LEFT JOIN employees e + LEFT JOIN employee e ON (a.employee_id = e.id) $makemodeljoin WHERE $invwhere|; @@ -1242,7 +1242,7 @@ sub all_parts { USING (entity_id) LEFT JOIN partsgroup pg ON (p.partsgroup_id = pg.id) - LEFT JOIN employees e + LEFT JOIN employee e ON (a.person_id = e.entity_id) $makemodeljoin WHERE $invwhere|; @@ -1308,7 +1308,7 @@ sub all_parts { USING (entity_id) LEFT JOIN partsgroup pg ON (p.partsgroup_id = pg.id) - LEFT JOIN employees e + LEFT JOIN employee e ON (a.employee_id = e.id) $makemodeljoin WHERE $ordwhere @@ -1348,7 +1348,7 @@ sub all_parts { ON (a.vendor_id = ct.id) LEFT JOIN partsgroup pg ON (p.partsgroup_id = pg.id) - LEFT JOIN employees e + LEFT JOIN employee e ON (a.employee_id = e.id) $makemodeljoin WHERE $ordwhere @@ -1414,7 +1414,7 @@ sub all_parts { USING (entity_id) LEFT JOIN partsgroup pg ON (p.partsgroup_id = pg.id) - LEFT JOIN employees e + LEFT JOIN employee e ON (a.employee_id = e.id) $makemodeljoin WHERE $quowhere @@ -1454,7 +1454,7 @@ sub all_parts { ON (a.vendor_id = ct.id) LEFT JOIN partsgroup pg ON (p.partsgroup_id = pg.id) - LEFT JOIN employees e + LEFT JOIN employee e ON (a.employee_id = e.id) $makemodeljoin WHERE $quowhere diff --git a/LedgerSMB/IS.pm b/LedgerSMB/IS.pm index 6d3cc7cc..a2857661 100644 --- a/LedgerSMB/IS.pm +++ b/LedgerSMB/IS.pm @@ -1761,7 +1761,7 @@ sub retrieve_invoice { a.entity_id, a.language_code, a.ponumber FROM ar a - LEFT JOIN employees e ON (e.entity_id = a.employee_id) + LEFT JOIN employee e ON (e.entity_id = a.employee_id) WHERE a.id = ?|; $sth = $dbh->prepare($query); diff --git a/LedgerSMB/JC.pm b/LedgerSMB/JC.pm index 0fdbcdb9..c9addc51 100644 --- a/LedgerSMB/JC.pm +++ b/LedgerSMB/JC.pm @@ -67,7 +67,7 @@ sub get_jcitems { pr.production, pr.completed, pr.parts_id AS project FROM jcitems j - JOIN employees e ON (e.id = j.employee_id) + JOIN employee e ON (e.id = j.employee_id) JOIN parts p ON (p.id = j.parts_id) JOIN project pr ON (pr.id = j.project_id) WHERE j.id = ?|; @@ -480,7 +480,7 @@ sub jcitems { FROM jcitems j JOIN parts p ON (p.id = j.parts_id) JOIN project pr ON (pr.id = j.project_id) - JOIN employees e ON (e.id = j.employee_id) + JOIN employee e ON (e.id = j.employee_id) WHERE $where ORDER BY employee, employeenumber, $sortorder|; diff --git a/LedgerSMB/OE.pm b/LedgerSMB/OE.pm index 6294236b..f3838c13 100644 --- a/LedgerSMB/OE.pm +++ b/LedgerSMB/OE.pm @@ -83,8 +83,8 @@ sub transactions { m.name AS manager, o.curr, o.ponumber FROM oe o JOIN $form->{vc} ct ON (o.$form->{vc}_id = ct.id) - LEFT JOIN employees e ON (o.employee_id = e.id) - LEFT JOIN employees m ON (e.managerid = m.id) + LEFT JOIN employee e ON (o.employee_id = e.id) + LEFT JOIN employee m ON (e.managerid = m.id) LEFT JOIN exchangerate ex ON (ex.curr = o.curr AND ex.transdate = o.transdate) WHERE o.quotation = ? @@ -138,7 +138,7 @@ sub transactions { } $query .= qq| - LEFT JOIN employees e ON (o.employee_id = e.id) + LEFT JOIN employee e ON (o.employee_id = e.id) LEFT JOIN exchangerate ex ON (ex.curr = o.curr AND ex.transdate = o.transdate) @@ -765,7 +765,7 @@ sub retrieve { o.ponumber FROM oe o JOIN $form->{vc} vc ON (o.$form->{vc}_id = vc.id) - LEFT JOIN employees e ON (o.employee_id = e.id) + LEFT JOIN employee e ON (o.employee_id = e.id) LEFT JOIN department d ON (o.department_id = d.id) WHERE o.id = ?|; $sth = $dbh->prepare($query); diff --git a/LedgerSMB/PE.pm b/LedgerSMB/PE.pm index d49c1cc3..377a1c52 100644 --- a/LedgerSMB/PE.pm +++ b/LedgerSMB/PE.pm @@ -1490,7 +1490,7 @@ sub get_jcitems { p.partnumber FROM jcitems j JOIN project pr ON (pr.id = j.project_id) - JOIN employees e ON (e.id = j.employee_id) + JOIN employee e ON (e.id = j.employee_id) JOIN parts p ON (p.id = j.parts_id) LEFT JOIN $form->{vc} c ON (c.id = pr.$form->{vc}_id) WHERE pr.parts_id IS NULL diff --git a/LedgerSMB/RP.pm b/LedgerSMB/RP.pm index 4bdd4360..706b5b0c 100644 --- a/LedgerSMB/RP.pm +++ b/LedgerSMB/RP.pm @@ -2337,7 +2337,7 @@ sub payments { FROM acc_trans ac JOIN $form->{db} a ON (ac.trans_id = a.id) JOIN $table c ON (c.id = a.${table}_id) - LEFT JOIN employees e ON (a.employee_id = e.id) + LEFT JOIN employee e ON (a.employee_id = e.id) $dpt_join WHERE ac.chart_id = $ref->{id} $where|; @@ -2364,7 +2364,7 @@ sub payments { FROM acc_trans ac JOIN gl g ON (g.id = ac.trans_id) LEFT - JOIN employees e ON (g.employee_id = e.id) + JOIN employee e ON (g.employee_id = e.id) $dpt_join WHERE ac.chart_id = $ref->{id} $glwhere AND (ac.amount * $ml) > 0 |