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

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



Revision: 6296
          http://sourceforge.net/p/ledger-smb/code/6296
Author:   einhverfr
Date:     2013-11-21 05:40:07 +0000 (Thu, 21 Nov 2013)
Log Message:
-----------
Improvements to counterparty handling

Modified Paths:
--------------
    addons/1.3/wxPOS/WXPOS/State.pm

Added Paths:
-----------
    addons/1.3/wxPOS/WXPOS/Counterparty.pm
    addons/1.3/wxPOS/WXPOS/UI/Contact.pm

Added: addons/1.3/wxPOS/WXPOS/Counterparty.pm
===================================================================
--- addons/1.3/wxPOS/WXPOS/Counterparty.pm	                        (rev 0)
+++ addons/1.3/wxPOS/WXPOS/Counterparty.pm	2013-11-21 05:40:07 UTC (rev 6296)
@@ -0,0 +1,147 @@
+=head1 NAME
+
+WXPOS::Counterparty - Customer/vendor routines for LedgerSMB's wxPOS.
+
+=head1 SYNOPSIS
+
+To look up a customer
+
+  my $part = WXPOS::Counterparty->get($customer_id, 2);
+
+To search for a vendor
+
+  my $part = WXPOS::Counterparty->search($name, 1);
+
+Saving is not yet supported.
+
+=cut
+
+package WXPOS::Counterparty;
+use Moo;
+with 'WXPOS::PGObject';
+
+=head1 DESCRIPTION
+
+This is the common set of routines for handling customers and vendors, i.e. 
+counterparties to transactions.  Currently only reading is supported.
+
+=head1 PROPERTIES
+
+=over
+
+=item id int
+
+corresponds to the entity_credit_account.id in the database
+
+=item name string
+
+entity.name
+
+=item pay_to string
+
+entity_credit_account.pay_to
+
+=item email
+
+eca_to_contact.contact
+
+=item phone
+
+eca_to_contact.contact
+
+=item entity_class
+
+entity_credit_account.entity_class
+
+=back
+
+More properties will need to be added if support is added for writing customer
+records.
+
+=cut
+
+has id => (is => 'ro', required => 1); 
+    # required will change to 0 if we support saving counterparties
+
+has name => (is => 'ro', required => 1);
+
+has pay_to => (is => 'ro', required => 0);
+
+has entity_class => (is => 'ro', required => 0);
+has email => (is => 'ro', required => 0);
+has phone => (is => 'ro', required => 0);
+
+sub _get_prefix {
+    return 'wxpos_counterparty__';
+}
+
+=head1 METHODS
+
+=head2 get($id, $class)
+
+Returns the customer with the id, of the class listed.  1 for vendors 2 for
+customers.
+
+=cut
+
+sub get{
+    my ($self, $id, $class) = @_;
+    my ($ref) = __PACKAGE__->call_procedure(funcname => 'get', 
+                                          funcprefix => _get_prefix(),
+                                                args => [$id, $class]);
+    return __PACKAGE__->new(%$ref);
+}
+
+=head2 search($name, $class)
+
+Returns a set of matching customers based on the name, of the class listed.
+
+=cut
+
+sub search {
+    my ($self, $name, $class) = @_;
+    my @results = __PACKAGE__->call_procedure(funcname => 'search',
+                                            funcprefix => _get_prefix(),
+                                                  args => [$name, $class]);
+    for my $ref (@results){
+        $ref = __PACKAGE__->new(%$ref);
+    }
+    return @results;
+}
+
+=head2 save()
+
+Saves the information along with the contact info.
+
+=cut
+
+sub save {
+    my ($self) = @_;
+    # Save customer info
+    my ($company) = $self->call_dbmethod(funcname => 'company__save', 
+                             args => {legal_name => $self->name}
+    );
+    my ($eca) = $self->call_dbmethod(funcname => 'entity_credit_save',
+                                         args => $company);
+    # Save contact info
+    $self->call_dbmethod(funcname => 'eca__save_contact',
+                             args => {credit_id => $eca->{id},
+                                  contact_class => 1,
+                                        contact => $self->phone,
+                                     } ) if $self->phone;
+    $self->call_dbmethod(funcname => 'eca__save_contact',
+                             args => {credit_id => $eca->{id},
+                                  contact_class => 12,
+                                        contact => $self->email,
+                                     } ) if $self->email;
+}
+
+=head1 COPYRIGHT
+
+COPYRIGHT(C) 2013 The LedgerSMB Core Team.  This File may be re-used under the
+terms of the General Public License version 2 or at your option any later
+version.  Please see the included LICENSE.txt for more information.
+
+=cut
+
+1;

Modified: addons/1.3/wxPOS/WXPOS/State.pm
===================================================================
--- addons/1.3/wxPOS/WXPOS/State.pm	2013-11-18 14:09:40 UTC (rev 6295)
+++ addons/1.3/wxPOS/WXPOS/State.pm	2013-11-21 05:40:07 UTC (rev 6296)
@@ -17,6 +17,11 @@
 
 User information.
 
+=head2 Args
+
+Temporary holding place for args to be passed to the next window.  This
+should be unset as soon as read.
+
 =head1 FUNCTIONS
 
 =head2 clear
@@ -38,6 +43,7 @@
 our $DBH;
 our $User;
 our $Notebook;
+our $args;
 
 sub clear {
     $DBH->disconnect;

Added: addons/1.3/wxPOS/WXPOS/UI/Contact.pm
===================================================================
--- addons/1.3/wxPOS/WXPOS/UI/Contact.pm	                        (rev 0)
+++ addons/1.3/wxPOS/WXPOS/UI/Contact.pm	2013-11-21 05:40:07 UTC (rev 6296)
@@ -0,0 +1,125 @@
+package WXPOS::UI::Contact;
+use Wx qw(:frame :textctrl :sizer :panel :window :id);
+use Wx::Event qw(EVT_BUTTON EVT_TEXT EVT_LISTBOX_DCLICK EVT_COMBOBOX EVT_LIST_ITEM_RIGHT_CLICK EVT_LIST_ITEM_SELECTED EVT_LIST_ITEM_DESELECTED);
+use base qw(Wx::Frame);
+use Wx::Grid;
+use WXPOS::AR;
+use WXPOS::AP;
+use WXPOS::Counterparty;
+use lib 'scripts';
+
+sub new {
+    my ($class, $sesion, $action, $entity_class) = @_;
+    my $self = {};
+    $self->{sesion} = $sesion;
+    bless $self, $class;
+    return $self->$action($entity_class);
+}
+
+# New Customer/Vendor Screen
+sub Contact {
+    my ($self, $entity_class);
+    $self->{entity_class} = $self->{entity_class};
+    # Close button
+    my $close_btn = Wx::Button->new($self->{tab}, -1, '[X]', 
+                           [750, 3], [30, 24]
+    );
+    EVT_BUTTON($self->{tab}, $close_btn, sub{$self->_close_pane});
+    # Main Sizer
+    my $mainsizer = Wx::BoxSizer->new(wxHORIZONTAL);
+    $self->{mainpanel} = Wx::Panel->new(
+        $self->{tab}, -1, [-1,-1], [-1,-1],
+        wxTAB_TRAVERSAL|wxBORDER_NONE
+    );
+    # Customer/Contact Sizer
+    my $contactsizer = Wx::BoxSizer->new(wxVERTICAL);
+     # Name
+    my $namerowsizer = Wx::BoxSizer->new(wxHORIZONTAL);
+    my $name_lbl = Wx::StaticText->new($self->{tab}, -1, "Name:", 
+                         [-1, -1], [200, 2]);
+    $namerowsizer->Add($name_lbl, 1, wxEXPAND | wxALIGH_RIGHT, 0);
+
+    $self->{name} = Wx::TextCtrl->new(
+        $panel, -1, '',
+        [-1,-1],[300,60],
+        wxTE_MULTILINE
+    );
+    $namerowsizer->Add($self->{name}, 1, wxEXPAND | wxALIGH_LEFT, 0);
+    $contactsizer->add($namerowsizer, 0, wxALIGN_LEFT); 
+     # Phone Number
+    my $telrowsizer = Wx::BoxSizer->new(wxHORIZONTAL);
+    my $tel_lbl = Wx::StaticText->new($self->{tab}, -1, "Tel:", 
+                         [-1, -1], [200, 2]);
+    $telrowsizer->Add($tel_lbl, 1, wxEXPAND | wxALIGH_RIGHT, 0);
+
+    $self->{tel} = Wx::TextCtrl->new(
+        $panel, -1, '',
+        [-1,-1],[300,60],
+        wxTE_MULTILINE
+    );
+    $namerowsizer->Add($self->{tel}, 1, wxEXPAND | wxALIGH_LEFT, 0);
+    $contactsizer->add($telrowsizer, 0, wxALIGN_LEFT); 
+
+     # Email
+    my $emailrowsizer = Wx::BoxSizer->new(wxHORIZONTAL);
+    my $email_lbl = Wx::StaticText->new($self->{tab}, -1, "Email:", 
+                         [-1, -1], [200, 2]);
+    $emailrowsizer->Add($email_lbl, 1, wxEXPAND | wxALIGH_RIGHT, 0);
+
+    $self->{email} = Wx::TextCtrl->new(
+        $panel, -1, '',
+        [-1,-1],[300,60],
+        wxTE_MULTILINE
+    );
+    $emailrowsizer->Add($self->{email}, 1, wxEXPAND | wxALIGH_LEFT, 0);
+    $contactsizer->add($emailrowsizer, 0, wxALIGN_LEFT); 
+
+    $mainsizer->Add($contactsizer, 0, wx_ALIGN_CENTER);
+    # Address Sizer
+    # TODO
+     # Address lines (3)
+     # City State Zip
+    # Button row
+    my $close_btn = Wx::Button->new($self->{tab}, -1, '[X]', 
+                                                       [750, 3], [30, 24]);
+    EVT_BUTTON($self->{tab}, $close_btn, sub{$self->_close_pane});
+
+    my $save_btn = Wx::Button->new($self->{tab}, -1, 'Invoice', 
+    EVT_BUTTON($self->{tab}, $save_btn, sub{$self->_add_invoice});
+                                                       [700, 550], [30, 24]);
+}
+
+sub _add_invoice {
+    my ($self) = @_;
+    $self->_save;
+    $self->_close_pane;
+    my $nb = $WXPOS::State::Notebook;
+    $WXPOS::State::Args = {name => $self->{name}->GetValue};
+    if ($self->{entity_class} == 2){
+        $nb->AddPage(WXPOS::UI::AR->new($self->{parent_window}->{sesion},
+                                        'Invoice'), 'Invoice', 1);
+    } else {
+        $nb->AddPage(WXPOS::UI::AP->new($self->{parent_window}->{sesion},
+                                        'Invoice'), 'Invoice', 1);
+    }
+}
+
+sub _save {
+    my ($self) = @_;
+    my %args = ();
+    $args{entity_class} = $self->{entity_class};
+    $args{name} = $self->{name}->GetValue;
+    $args{phone} = $self->{tel}->GetValue;
+    $args{email} = $self->{email}->GetValue;
+    my $contact = WXPOS::Counterparty->new(%args);
+    $contact->save; 
+}
+
+sub _close_pane {
+    my ($self) = $_;
+    my $selection = $WXPOS::State::Notebook->GetSelection;
+    $WXPOS::State::Notebook->DeletePage($selection);
+    return 1;
+}
+
+1;

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


------------------------------------------------------------------------------
Shape the Mobile Experience: Free Subscription
Software experts and developers: Be at the forefront of tech innovation.
Intel(R) Software Adrenaline delivers strategic insight and game-changing 
conversations that shape the rapidly evolving mobile landscape. Sign up now. 
http://pubads.g.doubleclick.net/gampad/clk?id=63431311&iu=/4140/ostg.clktrk
_______________________________________________
Ledger-smb-commits mailing list
..hidden..
https://lists.sourceforge.net/lists/listinfo/ledger-smb-commits