[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

SF.net SVN: ledger-smb:[6177] addons/1.3/wxPOS



Revision: 6177
          http://sourceforge.net/p/ledger-smb/code/6177
Author:   einhverfr
Date:     2013-10-24 10:17:30 +0000 (Thu, 24 Oct 2013)
Log Message:
-----------
I can now log in with new code:
1.  Have moved from entity notes to a json field for pos profile
2.  Now depend on JSON.pm and PGObject::Simple::Role.

Modified Paths:
--------------
    addons/1.3/wxPOS/scripts/LSMBDB.pm
    addons/1.3/wxPOS/scripts/Login.pm

Added Paths:
-----------
    addons/1.3/wxPOS/scripts/WXPOS/
    addons/1.3/wxPOS/scripts/WXPOS/State.pm
    addons/1.3/wxPOS/scripts/WXPOS/User.pm
    addons/1.3/wxPOS/setup/
    addons/1.3/wxPOS/setup/functions.sql
    addons/1.3/wxPOS/setup/schema.sql

Modified: addons/1.3/wxPOS/scripts/LSMBDB.pm
===================================================================
--- addons/1.3/wxPOS/scripts/LSMBDB.pm	2013-10-24 04:36:00 UTC (rev 6176)
+++ addons/1.3/wxPOS/scripts/LSMBDB.pm	2013-10-24 10:17:30 UTC (rev 6177)
@@ -14,7 +14,9 @@
 =cut
 
 package LSMBDB;
+use WXPOS::State;
 use DBI;
+use Carp::Always;
 
 =item new (USER, PASSWORD, COMPANY, HOST)
 
@@ -28,6 +30,7 @@
  my $self = {};
  $self->{dbh} = DBI->connect("dbi:Pg:dbname=$comp;host=$host", $user, $pass, {RaiseError => 0, AutoCommit => 0});
  if ($self->{dbh}) {
+  $WXPOS::State::DBH = $self->{dbh};
   bless $self, $class;
   return $self;
  }

Modified: addons/1.3/wxPOS/scripts/Login.pm
===================================================================
--- addons/1.3/wxPOS/scripts/Login.pm	2013-10-24 04:36:00 UTC (rev 6176)
+++ addons/1.3/wxPOS/scripts/Login.pm	2013-10-24 10:17:30 UTC (rev 6177)
@@ -34,6 +34,9 @@
 use Wx::Event qw(EVT_BUTTON);
 use Wx qw(wxDefaultPosition wxDefaultSize wxOK wxCENTRE wxTE_PASSWORD wxCLOSE_BOX wxBITMAP_TYPE_PNG);
 
+use LSMBDB;
+use WXPOS::User;
+
 sub new {
  my ($class) = @_;
  my $self = Wx::Dialog->new(undef , -1, "LedgerSMB", wxDefaultPosition, [300, 320]);
@@ -61,10 +64,15 @@
  $self->{sesion}->{comp} = $self->{comp}->GetValue();
  $self->{sesion}->{serv} = $self->{serv}->GetValue();
  my $pass = $self->{pass}->GetValue();
- use LSMBDB;
- $self->{sesion}->{ldb} = LSMBDB->new($self->{sesion}->{user}, $pass, $self->{sesion}->{comp}, $self->{sesion}->{serv});
+
+ $self->{sesion}->{ldb} = LSMBDB->new(
+         $self->{sesion}->{user}, $pass, $self->{sesion}->{comp}, 
+         $self->{sesion}->{serv}
+ );
+
  if ( $self->{sesion}->{ldb} ) {
-  $self->{sesion}->{user_info} = $self->{sesion}->{ldb}->getUserByUsername($self->{sesion}->{user});
+  my $uhandle = WXPOS::User->new();
+  $self->{sesion}->{user_info} = $uhandle->get_current;
   if ($self->{sesion}->{user_info}) {
    $self->EndModal(0);
   }

Added: addons/1.3/wxPOS/scripts/WXPOS/State.pm
===================================================================
--- addons/1.3/wxPOS/scripts/WXPOS/State.pm	                        (rev 0)
+++ addons/1.3/wxPOS/scripts/WXPOS/State.pm	2013-10-24 10:17:30 UTC (rev 6177)
@@ -0,0 +1,46 @@
+=head1 NAME
+
+WXPOS::State - Semi-Global Namespace for WXPOS
+
+=head1 SYNPOSIS
+
+  my $dbh = $WXPOS::State::DBI;
+  WXPOS::State::clear();
+
+=head1 VARIABLES
+
+=head2 DBH
+
+This is the database handle.
+
+=head2 User
+
+User information.
+
+=head1 FUNCTIONS
+
+=head2 clear
+
+Clears state.
+
+=head1 COPYRIGHT
+
+Copyright (C) 2013 Chris Travers. This module may be used in accordance with 
+the GNU General Public License version 2 or at your option any later version.
+Please see the enclosed LICENSE.TXT for more information.
+
+=cut
+
+use strict;
+use warnings;
+package WXPOS::State;
+
+our $DBH;
+our $User;
+
+sub clear {
+    $DBH->disconnect;
+    $User = undef;
+}
+
+1;

Added: addons/1.3/wxPOS/scripts/WXPOS/User.pm
===================================================================
--- addons/1.3/wxPOS/scripts/WXPOS/User.pm	                        (rev 0)
+++ addons/1.3/wxPOS/scripts/WXPOS/User.pm	2013-10-24 10:17:30 UTC (rev 6177)
@@ -0,0 +1,130 @@
+=head1 NAME
+
+WXPOS::User - User handling for LedgerSMB's WXPOS.
+
+=head1 SYNPOSIS
+
+ my $user = WXPOS::User->get_current;
+
+ my $user = WXPOS::User->get_by_username($username);
+
+ $user->save_preferences;
+
+=cut
+
+package WXPOS::User;
+use JSON;
+use Moo;
+use WXPOS::State;
+with 'PGObject::Simple::Role';
+
+=head1 PROPERTIES
+
+=over
+
+=item username 
+
+User's username
+
+=item name 
+
+User's full name
+
+=item ssn 
+
+Social security or tax id for the user.
+
+=item defaults
+
+Hash ref of defaults for the software.
+
+=back
+
+=cut
+
+has username => (is => 'ro');
+
+has name => (is => 'ro');
+
+has ssn => (is => 'ro');
+
+has defaults => (is => 'rw');
+
+=head1 METHODS
+
+=cut
+
+# Private method _process_defaults(json) takes a single json string in and
+# returns the json object as a hashref.
+#
+# This is a simple wrapper around JSON.pm for mere abstraction and portability
+
+sub _process_defaults {
+    my ($json)  = @_;
+    return JSON->new->utf8->decode($json)
+}
+
+# Private method _get_prefix used to set prefix in db
+
+sub _get_prefix {
+    return 'wxpos_user__';
+}
+
+# Private method to get the database handle
+
+sub _get_dbh {
+    return $WXPOS::State::DBH;
+}
+
+=head2 get_current
+
+This returns the user associated with the current user.
+
+=cut
+
+sub get_current {
+    my ($self) = @_;
+    my ($ref) 
+     = $self->call_dbmethod(funcname => 'get_current', funcschema => 'public');
+    $ref->{defaults} = _process_defaults($ref->{defaults}) if $ref->{defaults};
+    return $self->new(%$ref);
+}
+
+
+=head2 get_by_username(username)
+
+This returns a user by username
+
+=cut
+
+sub get_by_username {
+    my ($self, $username) = @_;
+    my ($ref) 
+     = $self->call_dbmethod(funcname => 'get_current', 
+                          funcschema => 'public',
+                                args => {username => $username});
+    $ref->{defaults} = _process_defaults($ref->{defaults}) if $ref->{defaults};
+    return $self->new(%$ref);
+}
+
+=head2 save_defaults
+
+This saves the current user's defaults
+
+=cut
+
+sub save_defaults {
+    my ($self) = @_;
+    $self->call_dbmethod(funcname => 'save_defaults',
+                       funcschema => 'public');
+}
+
+=head1 COPYRIGHT
+
+COPYRIGHT (C) 2013, Chris Travers.  This file may be used in accordance with 
+the GNU General Public License version 2 or at your version any later version.
+Please see the enclosed LICENSE.TXT for details.
+
+=cut
+
+1;

Added: addons/1.3/wxPOS/setup/functions.sql
===================================================================
--- addons/1.3/wxPOS/setup/functions.sql	                        (rev 0)
+++ addons/1.3/wxPOS/setup/functions.sql	2013-10-24 10:17:30 UTC (rev 6177)
@@ -0,0 +1,46 @@
+BEGIN;
+
+DROP TYPE IF EXISTS wxpos_user CASCADE;
+
+CREATE TYPE wxpos_user AS (
+    username text,
+    name text,
+    ssn text,
+    defaults json
+);
+
+CREATE OR REPLACE FUNCTION wxpos_user__get_by_username(in_username text)
+returns wxpos_user
+language sql as
+$$
+SELECT u.username, e.name, ee.ssn, up.wx_profile as defaults
+  FROM users u 
+  JOIN user_preference up ON up.id = u.id
+  JOIN entity e ON (u.entity_id = e.id) 
+  JOIN entity_employee ee ON (e.id = ee.entity_id)
+ WHERE u.username = $1;
+$$;
+
+CREATE OR REPLACE FUNCTION wxpos_user__get_current()
+RETURNS wxpos_user
+language sql as
+$$
+SELECT wxpos_user__get_by_username(SESSION_USER::text);
+$$; 
+
+CREATE OR REPLACE FUNCTION wxpos_user__set_defaults
+(in_username text, in_defaults json)
+RETURNS BOOL LANGUAGE SQL AS
+$$
+UPDATE user_preference
+   SET wx_profile = $2
+ WHERE id IN (select id from users where username = $1);
+
+SELECT count(*) = 1
+  FROM user_preference
+ WHERE id IN (select id from users where username = $1);
+$$;
+
+
+
+COMMIT;

Added: addons/1.3/wxPOS/setup/schema.sql
===================================================================
--- addons/1.3/wxPOS/setup/schema.sql	                        (rev 0)
+++ addons/1.3/wxPOS/setup/schema.sql	2013-10-24 10:17:30 UTC (rev 6177)
@@ -0,0 +1,5 @@
+BEGIN;
+
+ALTER TABLE user_preference ADD wx_profile json;
+
+COMMIT;

This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.


------------------------------------------------------------------------------
October Webinars: Code for Performance
Free Intel webinars can help you accelerate application performance.
Explore tips for MPI, OpenMP, advanced profiling, and more. Get the most from 
the latest Intel processors and coprocessors. See abstracts and register >
http://pubads.g.doubleclick.net/gampad/clk?id=60135991&iu=/4140/ostg.clktrk
_______________________________________________
Ledger-smb-commits mailing list
..hidden..
https://lists.sourceforge.net/lists/listinfo/ledger-smb-commits