[Ledger-smb-devel] [PATCH] Misc patches for a bunch of little issues with 1.3

2010-10-12 Thread John Locke
---
 LedgerSMB/HR.pm   |   40 
 LedgerSMB/PriceMatrix.pm  |8 
 LedgerSMB/Setting.pm  |2 +-
 UI/payments/payment2.html |4 ++--
 sql/Pg-database.sql   |6 +-
 sql/modules/Account.sql   |2 +-
 6 files changed, 33 insertions(+), 29 deletions(-)

diff --git a/LedgerSMB/HR.pm b/LedgerSMB/HR.pm
index 2fbd297..54a5a09 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 employee e WHERE e.id = ?|;
+$query = qq|SELECT e.* FROM employee e WHERE e.employeenumber = ?|;
 $sth   = $dbh-prepare($query);
 $sth-execute( $form-{id} )
   || $form-dberror( __FILE__ . ':' . __LINE__ . ':' . $query );
@@ -61,10 +61,10 @@ sub get_employee {
 $sth-finish;
  # get manager
-$form-{managerid} *= 1;
+$form-{manager_id} *= 1;
 -$sth = $dbh-prepare(SELECT name FROM employee WHERE id = ?);
-$sth-execute( $form-{managerid} );
+$sth = $dbh-prepare(SELECT first_name FROM employee WHERE
entity_id = ?);
+$sth-execute( $form-{manager_id} );
 ( $form-{manager} ) = $sth-fetchrow_array;
  $notid = qq|AND id != | . $dbh-quote( $form-{id} );
@@ -78,7 +78,7 @@ sub get_employee {
  # get managers
 $query = qq|
- SELECT id, name
+ SELECT entity_id, first_name
FROM employee
   WHERE sales = '1'
 AND role = 'manager'
@@ -110,11 +110,11 @@ sub save_employee {
 my $uid = localtime;
 $uid .= $$;
 -$query = qq|INSERT INTO employee (name) VALUES ('$uid')|;
+$query = qq|INSERT INTO employee (first_name) VALUES ('$uid')|;
 $dbh-do($query)
   || $form-dberror( __FILE__ . ':' . __LINE__ . ':' . $query );
 -$query = qq|SELECT id FROM employee WHERE name = '$uid'|;
+$query = qq|SELECT entity_id FROM employee WHERE first_name =
'$uid'|;
 $sth   = $dbh-prepare($query);
 $sth-execute
   || $form-dberror( __FILE__ . ':' . __LINE__ . ':' . $query );
@@ -123,15 +123,15 @@ sub save_employee {
 $sth-finish;
 }
 -my ( $null, $managerid ) = split /--/, $form-{manager};
-$managerid *= 1;
+my ( $null, $manager_id ) = split /--/, $form-{manager};
+$manager_id *= 1;
 $form-{sales} *= 1;
   $query = qq|
UPDATE employeeSET employeenumber = ?,
-  name = ?,
+  first_name = ?,
   address1 = ?,
   address2 = ?,
   city = ?,
@@ -150,20 +150,20 @@ sub save_employee {
   dob = ?,
   iban = ?,
   bic = ?,
-  managerid = ?
+  manager_id = ?
 WHERE id = ?|;
 $sth = $dbh-prepare($query);
 $form-{dob}   ||= undef;
 $form-{startdate} ||= undef;
 $form-{enddate}   ||= undef;
 $sth-execute(
-$form-{employeenumber}, $form-{name},  $form-{address1},
+$form-{employeenumber}, $form-{first_name},
$form-{address1},
 $form-{address2},   $form-{city},  $form-{state},
 $form-{zipcode},$form-{country},   $form-{workphone},
 $form-{homephone},  $form-{startdate}, $form-{enddate},
 $form-{notes},  $form-{role},  $form-{sales},
 $form-{email},  $form-{ssn},   $form-{dob},
-$form-{iban},   $form-{bic},   $managerid,
+$form-{iban},   $form-{bic},   $manager_id,
 $form-{id}
 ) || $form-dberror( __FILE__ . ':' . __LINE__ . ':' . $query );
 @@ -196,8 +196,8 @@ sub employees {
 my $dbh = $form-{dbh};
  my $where = 1 = 1;
-$form-{sort} = ( $form-{sort} ) ? $form-{sort} : name;
-my @a = qw(name);
+$form-{sort} = ( $form-{sort} ) ? $form-{sort} : first_name;
+my @a = qw(first_name);
 my $sortorder = $form-sort_order( \...@a );
  my $var;
@@ -209,9 +209,9 @@ sub employees {
 if ( $form-{startdateto} ) {
 $where .=  AND e.startddate =  . $dbh-quote(
$form-{startdateto} );
 }
-if ( $form-{name} ne  ) {
-$var = $dbh-quote( $form-like( lc $form-{name} ) );
-$where .=  AND lower(e.name) LIKE $var;
+if ( $form-{first_name} ne  ) {
+$var = $dbh-quote( $form-like( lc $form-{first_name} ) );
+$where .=  AND lower(e.first_name) LIKE $var;
 }
 if ( $form-{notes} ne  ) {
 $var = $dbh-quote( $form-like( lc $form-{notes} ) );
@@ -231,9 +231,9 @@ sub employees {
 }
  my $query = qq|
-  SELECT e.*, m.name AS manager
+  SELECT e.*, m.first_name AS manager
 FROM employee e
-   LEFT 

[Ledger-smb-devel] Notes on updating to 1.3 trunk

2010-10-12 Thread John Locke
 Hi,

I've spent the past couple days trying to migrate to 1.3, and I hit a
ton of issues. Even now, the system is only partially usable -- lots
more bugs to squash. Just thought I'd post my notes so far, maybe with
some others doing this we can get 1.3 out the door.

Many thanks to Chris T for some ongoing assistance with this... I've
learned a ton about Postgres and the data structure of Ledger.

Here we go:

Starting state:
- Server already configured for Apache, CGI, CPAN dependencies, and
aliases set to a working copy that mirrors SVN trunk
- perl Makefile
- make
- resolve most issues, though still lots of failing tests
- tried initiate.pl, got partly there, ended up ditching everything and
starting over with INSTALL.manual steps.

New site install:

1. Install specified contrib templates from
/usr/share/postgresql/8.3/contrib into template1
2. Create database
3. \i sql/Pg-database.sql
4. Import functions from sql/modules/LOADORDER
5. Import other sql/modules files: EndOfYear.sql, Inventory.sql,
security.sql, Settings.sql, Vendor.sql

6. Generate custom roles file from Roles.sql, import.

7. select admin__save_user(null, person__save(null, 3,
'firstname','middle','last', 232), 'mylogin','mypass'); -- 232 is id for
USA in countries table

8. select admin__add_user_to_role('mylogin', rolname) from pg_roles
where rolname like 'lsmb_mydbname%';

9. grant select on account_link_description to
lsmb_mydbname__account_create -- lots more grants needed, may end up
granting all to my login for time being

10. Import old chart (using some other code leveraging another project,
load each chart id and account_save() account_heading_save() each account

11. alter schema public rename to newschema;

12. create schema public;

13. pg_restore -U postgres -d mydbname backup-from-1.2.sqlc

14. alter schema public rename to orig;

15. alter schema newschema rename to public;

16. Work my way through a SQL-Ledger migration script that Chris T
provided (Chris, mind if I post to the list?)

17. insert into parts select * from parts; -- repeat this copy for
assembly, partsgroup, makemodel, pricegroup, warehouse, invoice,
yearend, department

18. drop ar__audit_trail, ap__audit_trail on ar, drop gl_audit_trail on
gl -- couldn't import into ar, ap, gl due to missing grants

19. Import into ar, ap, gl from Chris's script

... that's where I've gotten. Sent a patch to the list earlier with some
other fixes I had to do...

The current result is I've got a partially working upgrade, but I'm
seeing lots of things that need fixing -- it looks like many old tables
have been replaced with views, but the columns don't match what the code
expects, lots of missing permissions, a few broken features (like all
period boxes seem to have no effect, have to enter dates in the fields
instead), reconciliation doesn't show up, etc.

Will post more as we work through it...

Cheers,

-- 
John Locke
Open Source Solutions for Small Business Problems
published by Charles River Media, June 2004
Follow me on Twitter: http://twitter.com/freelock
http://www.freelock.com


--
Beautiful is writing same markup. Internet Explorer 9 supports
standards for HTML5, CSS3, SVG 1.1,  ECMAScript5, and DOM L2  L3.
Spend less time writing and  rewriting code and more time creating great
experiences on the web. Be a part of the beta today.
http://p.sf.net/sfu/beautyoftheweb
___
Ledger-smb-devel mailing list
Ledger-smb-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ledger-smb-devel


[Ledger-smb-devel] [PATCH] Add new sproc for account_heading_get -- seems sloppy. Changed AM to use it for header accounts.

2010-10-12 Thread John Locke
---
 LedgerSMB/DBObject/Account.pm |9 +
 sql/modules/Account.sql   |   13 -
 2 files changed, 17 insertions(+), 5 deletions(-)

diff --git a/LedgerSMB/DBObject/Account.pm b/LedgerSMB/DBObject/Account.pm
index 509ca20..065c523 100644
--- a/LedgerSMB/DBObject/Account.pm
+++ b/LedgerSMB/DBObject/Account.pm
@@ -45,12 +45,13 @@ value must be properly set.
  sub get {
 my $self = shift @_;
-my @accounts =  $self-exec_method(funcname = 'account_get');
+my $func = 'account_get';
+if ($self-{charttype} and $self-{charttype} eq 'H'){
+  $func = 'account_heading_get';
+}
+my @accounts =  $self-exec_method(funcname = $func);
 $self-{account_list} = [];
 for my $ref (@accounts){
-if ($self-{charttype} and $self-{charttype} ne
$ref-{charttype}){
- next;
-}
 bless $ref, 'LedgerSMB::DBObject::Account';
 $ref-merge($self, keys = ['_user', '_locale', 'stylesheet',
'dbh', '_roles', '_request']);
 push (@{$self-{account_list}}, $ref);
diff --git a/sql/modules/Account.sql b/sql/modules/Account.sql
index 1237fa1..7fff111 100644
--- a/sql/modules/Account.sql
+++ b/sql/modules/Account.sql
@@ -22,7 +22,18 @@ $$
 DECLARE
account chart%ROWTYPE;
 BEGIN
-   SELECT * INTO account FROM chart WHERE id = in_id;
+   SELECT * INTO account FROM chart WHERE id = in_id AND charttype = 'A';
+   RETURN account;
+END;
+$$ LANGUAGE plpgsql;
+
+
+CREATE OR REPLACE FUNCTION account_heading_get (in_id int) RETURNS chart AS
+$$
+DECLARE
+   account chart%ROWTYPE;
+BEGIN
+   SELECT * INTO account FROM chart WHERE id = in_id AND charttype = 'H';
RETURN account;
 END;
 $$ LANGUAGE plpgsql;

--
Beautiful is writing same markup. Internet Explorer 9 supports
standards for HTML5, CSS3, SVG 1.1,  ECMAScript5, and DOM L2  L3.
Spend less time writing and  rewriting code and more time creating great
experiences on the web. Be a part of the beta today.
http://p.sf.net/sfu/beautyoftheweb
___
Ledger-smb-devel mailing list
Ledger-smb-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ledger-smb-devel


Re: [Ledger-smb-devel] [PATCH] Misc patches for a bunch of little issues with 1.3

2010-10-12 Thread Chris Travers
Reviewing.
On Tue, Oct 12, 2010 at 9:14 AM, John Locke m...@freelock.com wrote:
 ---
  LedgerSMB/HR.pm           |   40 
  LedgerSMB/PriceMatrix.pm  |    8 
  LedgerSMB/Setting.pm      |    2 +-
  UI/payments/payment2.html |    4 ++--
  sql/Pg-database.sql       |    6 +-
  sql/modules/Account.sql   |    2 +-
  6 files changed, 33 insertions(+), 29 deletions(-)

 diff --git a/LedgerSMB/HR.pm b/LedgerSMB/HR.pm
 index 2fbd297..54a5a09 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 employee e WHERE e.id = ?|;
 +        $query = qq|SELECT e.* FROM employee e WHERE e.employeenumber = ?|;
         $sth   = $dbh-prepare($query);
         $sth-execute( $form-{id} )
           || $form-dberror( __FILE__ . ':' . __LINE__ . ':' . $query );
 @@ -61,10 +61,10 @@ sub get_employee {
         $sth-finish;
          # get manager
 -        $form-{managerid} *= 1;
 +        $form-{manager_id} *= 1;
  -        $sth = $dbh-prepare(SELECT name FROM employee WHERE id = ?);
 -        $sth-execute( $form-{managerid} );
 +        $sth = $dbh-prepare(SELECT first_name FROM employee WHERE
 entity_id = ?);
 +        $sth-execute( $form-{manager_id} );
         ( $form-{manager} ) = $sth-fetchrow_array;
          $notid = qq|AND id != | . $dbh-quote( $form-{id} );
 @@ -78,7 +78,7 @@ sub get_employee {
      # get managers
     $query = qq|
 -                 SELECT id, name
 +                 SELECT entity_id, first_name
                    FROM employee
                   WHERE sales = '1'
                         AND role = 'manager'
 @@ -110,11 +110,11 @@ sub save_employee {
         my $uid = localtime;
         $uid .= $$;
  -        $query = qq|INSERT INTO employee (name) VALUES ('$uid')|;
 +        $query = qq|INSERT INTO employee (first_name) VALUES ('$uid')|;
         $dbh-do($query)
           || $form-dberror( __FILE__ . ':' . __LINE__ . ':' . $query );
  -        $query = qq|SELECT id FROM employee WHERE name = '$uid'|;
 +        $query = qq|SELECT entity_id FROM employee WHERE first_name =
 '$uid'|;
         $sth   = $dbh-prepare($query);
         $sth-execute
           || $form-dberror( __FILE__ . ':' . __LINE__ . ':' . $query );
 @@ -123,15 +123,15 @@ sub save_employee {
         $sth-finish;
     }
  -    my ( $null, $managerid ) = split /--/, $form-{manager};
 -    $managerid     *= 1;
 +    my ( $null, $manager_id ) = split /--/, $form-{manager};
 +    $manager_id     *= 1;
     $form-{sales} *= 1;
       $query = qq|
                UPDATE employee                    SET employeenumber = ?,
 -                      name = ?,
 +                      first_name = ?,
                       address1 = ?,
                       address2 = ?,
                       city = ?,
 @@ -150,20 +150,20 @@ sub save_employee {
                       dob = ?,
                       iban = ?,
                       bic = ?,
 -                      managerid = ?
 +                      manager_id = ?
                 WHERE id = ?|;
     $sth = $dbh-prepare($query);
     $form-{dob}       ||= undef;
     $form-{startdate} ||= undef;
     $form-{enddate}   ||= undef;
     $sth-execute(
 -        $form-{employeenumber}, $form-{name},      $form-{address1},
 +        $form-{employeenumber}, $form-{first_name},
 $form-{address1},
         $form-{address2},       $form-{city},      $form-{state},
         $form-{zipcode},        $form-{country},   $form-{workphone},
         $form-{homephone},      $form-{startdate}, $form-{enddate},
         $form-{notes},          $form-{role},      $form-{sales},
         $form-{email},          $form-{ssn},       $form-{dob},
 -        $form-{iban},           $form-{bic},       $managerid,
 +        $form-{iban},           $form-{bic},       $manager_id,
         $form-{id}
     ) || $form-dberror( __FILE__ . ':' . __LINE__ . ':' . $query );
  @@ -196,8 +196,8 @@ sub employees {
     my $dbh = $form-{dbh};
      my $where = 1 = 1;
 -    $form-{sort} = ( $form-{sort} ) ? $form-{sort} : name;
 -    my @a         = qw(name);
 +    $form-{sort} = ( $form-{sort} ) ? $form-{sort} : first_name;
 +    my @a         = qw(first_name);
     my $sortorder = $form-sort_order( \...@a );
      my $var;
 @@ -209,9 +209,9 @@ sub employees {
     if ( $form-{startdateto} ) {
         $where .=  AND e.startddate =  . $dbh-quote(
 $form-{startdateto} );
     }
 -    if ( $form-{name} ne  ) {
 -        $var = $dbh-quote( $form-like( lc $form-{name} ) );
 -        $where .=  AND lower(e.name) LIKE $var;
 +    if ( $form-{first_name} ne  ) {
 +        $var = $dbh-quote( $form-like( lc $form-{first_name} ) );
 +        $where .=  AND lower(e.first_name) LIKE $var;
     }
     if ( $form-{notes} ne  ) {
         $var = $dbh-quote( $form-like( lc $form-{notes} ) );
 @@ -231,9 +231,9 @@ sub employees {
     }
      my $query = qq|
 -