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

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



Revision: 6925
          http://sourceforge.net/p/ledger-smb/code/6925
Author:   einhverfr
Date:     2014-03-05 05:09:22 +0000 (Wed, 05 Mar 2014)
Log Message:
-----------
Adding stock list support for wxpos

Modified Paths:
--------------
    addons/1.3/wxPOS/WXPOS/UI/IC.pm
    addons/1.3/wxPOS/WXPOS/UI.pm

Added Paths:
-----------
    addons/1.3/wxPOS/WXPOS/Stocklist.pm
    addons/1.3/wxPOS/setup/Parts.sql

Added: addons/1.3/wxPOS/WXPOS/Stocklist.pm
===================================================================
--- addons/1.3/wxPOS/WXPOS/Stocklist.pm	                        (rev 0)
+++ addons/1.3/wxPOS/WXPOS/Stocklist.pm	2014-03-05 05:09:22 UTC (rev 6925)
@@ -0,0 +1,78 @@
+=head1 NAME
+
+WXPOS::StockList - Stock List Handling for WXPOS
+
+=head1 SYNPOSIS
+
+   my @entries = WXPOS::StockList->search($partnumber, $description);
+
+=head1 DESCRIPTION
+
+This module provides the basic framework for displaying the stock list.  
+It currently provides no possibilities for manipulating the numbers.
+
+=head1 PROPERTIES
+
+=over
+
+=item id int
+
+The id in the parts table.
+
+=item partnumber str
+
+=item description str
+
+=item sellprice numeric
+
+=item onhand numeric
+
+=back
+
+=cut
+
+package WXPOS::Stocklist;
+use Moo;
+with 'WXPOS::PGObject';
+
+has id          => (is => 'ro');
+has partnumber  => (is => 'ro');
+has description => (is => 'ro');
+has sellprice   => (is => 'ro');
+has onhand      => (is => 'ro');
+
+sub _get_prefix { 'stocklist__' }
+
+
+=head1 METHODS
+
+=head2 search($partnumber, $description)
+
+Both of these are substring searches.
+
+=cut
+
+sub search {
+    my ($self, $partnumber, $description) = @_;
+    my $tmp = __PACKAGE__->new(
+          id => '',
+          partnumber => "$partnumber",
+          description => "$description",
+          sellprice   => '',
+          onhand      => ''
+    );
+    my @items = $tmp->call_dbmethod(funcname => 'search');
+    $_ =  __PACKAGE__->new(%$_) for @items;
+    return @items;
+}
+
+=head1 COPYRIGHT
+
+Copyright 2014 The LedgerSMB Core Team.
+
+This file may be used under the terms of the GNU General Public License version
+2 or at your option any later version.
+
+=cut
+
+1;

Modified: addons/1.3/wxPOS/WXPOS/UI/IC.pm
===================================================================
--- addons/1.3/wxPOS/WXPOS/UI/IC.pm	2014-03-04 13:14:29 UTC (rev 6924)
+++ addons/1.3/wxPOS/WXPOS/UI/IC.pm	2014-03-05 05:09:22 UTC (rev 6925)
@@ -37,16 +37,16 @@
 
 use base qw(Wx::Frame);
 use Wx::Event qw(EVT_BUTTON);
-use Wx qw(wxDefaultPosition wxDefaultSize wxMAXIMIZE wxCB_READONLY);
+use Wx qw(wxDefaultPosition wxDefaultSize wxMAXIMIZE wxCB_READONLY 
+       wxLC_REPORT wxLI_HORIZONTAL);
 use Wx::Grid;
+use WXPOS::Stocklist;
 
 sub new {
  my ($class, $sesion, $action) = @_;
  my $self = {};
  $self->{sesion} = $sesion;
- $self->{wh_dft_id} = $self->{sesion}->{defaults}->{wh};
  bless $self, $class;
- $self->_getWarehouses();
  return $self->$action();
 }
 
@@ -57,60 +57,53 @@
  return 1;
 }
 
-sub _getWarehouses {
+sub Stocklist {
  my ($self) = @_;
- $self->{wh_des}->{''} = '';
- foreach (@{$self->{sesion}->{ldb}->getWarehouseList()}) {
-  $self->{wh_des}->{$_->[1]} = $_->[0];
-  if ($_->[0] == $self->{wh_dft_id}) {
-   $self->{wh_dft_des} = $_->[1];
-  }
- }
- return $self;
-}
+ $self->{sesion}->{tk} = undef;
+ $self->{sesion}->{tk}->{items} = 0;
+ $self->{tab} = Wx::Panel->new($self->{sesion}->{nb}, -1, 
+                   wxDefaultPosition, wxDefaultSize);
 
-sub Parts {
- my ($self) = @_;
-### Close Window
- $self->{WxPanel} = Wx::Panel->new($self->{sesion}->{nb}, -1, wxDefaultPosition, wxDefaultSize, wxMAXIMIZE);
- my $close_btn = Wx::Button->new($self->{WxPanel}, -1, '[X]', [750, 3], [30, 24]);
- EVT_BUTTON($self->{WxPanel}, $close_btn, sub{$self->_close_pane});
- Wx::StaticText->new($self->{WxPanel}, -1, 'Number', [10, 20], [90, 24]);
- $self->{numb} = Wx::TextCtrl->new($self->{WxPanel}, -1, '', [110, 20], [90, 24]);
- Wx::StaticText->new($self->{WxPanel}, -1, 'Description', [10, 60], [90, 24]);
- $self->{desc} = Wx::TextCtrl->new($self->{WxPanel}, -1, '', [110, 60], [180, 24]);
- Wx::StaticText->new($self->{WxPanel}, -1, 'Warehouse', [310, 40], [90, 24]);
- $self->{wh} = Wx::ComboBox->new($self->{WxPanel}, -1, $self->{wh_dft_des}, [400, 40], [180, 24], [keys(%{$self->{wh_des}})]);
- my $button = Wx::Button->new($self->{WxPanel}, -1, 'Search', [110, 100], [60, 24]);
- EVT_BUTTON($self->{WxPanel}, $button, sub{$self->_listPartsByName});
- return $self->{WxPanel};
+### Close Window 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});
+
+### Parts info
+ Wx::StaticLine->new($self->{tab}, -1, [0, 0], [800, 2], wxLI_HORIZONTAL);
+ Wx::StaticText->new($self->{tab}, -1, 'Partnumber', [10, 10], [90, 24]);
+ $self->{partnumber} = 
+       Wx::TextCtrl->new($self->{tab}, -1, '', [110, 10], [90, 24]);
+ Wx::StaticText->new($self->{tab}, -1, 'Description', [210, 10], [90, 24]);
+ $self->{description} = 
+       Wx::TextCtrl->new($self->{tab}, -1, '', [310, 10], [190, 24]);
+ my $search = Wx::Button->new($self->{tab}, -1, 'Search', [510, 10], [90, 24]);
+ EVT_BUTTON($self->{tab}, $search , sub{$self->_get_stocklist});
+#### Stock list
+ $self->{list} = Wx::ListCtrl->new($self->{tab}, -1, [5, 50], [750, 450], wxLC_REPORT);
+ $self->{list}->InsertColumn(1, 'ID', 0, 80);
+ $self->{list}->InsertColumn(2, 'Number', 0, 80);
+ $self->{list}->InsertColumn(3, 'Description', 0, 250);
+ $self->{list}->InsertColumn(4, 'Price', 0, 100);
+ $self->{list}->InsertColumn(5, 'Onhand', 0, 100);
+ $self->{partnumber}->SetFocus();
+ $self->{listcount} = 0;
+ return $self->{tab};
 }
 
-sub _listPartsByName {
- my($self, $event) = @_;
- my $numb = $self->{numb}->GetValue();
- my $desc = $self->{desc}->GetValue();
- my $wh = $self->{wh_des}->{$self->{wh}->GetValue()};wxCB_READONLY
- $self->{list} = Wx::Grid->new($self->{WxPanel}, -1, [10, 160], [790, 480], wxCB_READONLY);
- $self->{list}->CreateGrid(0, 4);
- $self->{list}->SetColLabelValue(0, 'Number');
- $self->{list}->SetColSize(0, 100);
- $self->{list}->SetColLabelValue(1, 'Description');
- $self->{list}->SetColSize(1, 440);
- $self->{list}->SetColLabelValue(2, 'Warehouse');
- $self->{list}->SetColSize(2, 100);
- $self->{list}->SetColLabelValue(3, 'Qty');
- $self->{list}->SetColSize(3, 60);
- my $list = $self->{sesion}->{ldb}->getPartsList($numb, $desc, $wh);
- my $i = 0;
- foreach (@{$list}) {
-  $self->{list}->AppendRows();
-  $self->{list}->SetCellValue($i, 0, $_->[0]);
-  $self->{list}->SetCellValue($i, 1, $_->[1]);
-  $self->{list}->SetCellValue($i, 2, $_->[2]);
-  $self->{list}->SetCellValue($i, 3, $_->[3]);
-  $i++;
- }
- return $self->{list};
-}
+sub _get_stocklist {
+  my ($self) = @_;
+  my @stocklist = WXPOS::Stocklist->search(
+          $self->{partnumber}->GetValue,
+          $self->{description}->GetValue
+  );
+  for my $item(@stocklist){
+    my $pp = $self->{list}->InsertStringItem($self->{listcount}, $item->id);
+    $self->{list}->SetItem($pp, 1, $item->partnumber, -1);
+    $self->{list}->SetItem($pp, 2, $item->description, -1);
+    $self->{list}->SetItem($pp, 3, $item->sellprice, -1);
+    $self->{list}->SetItem($pp, 4, $item->onhand, -1);
+  }
+  warn scalar @stocklist;
+} 
+
 1;

Modified: addons/1.3/wxPOS/WXPOS/UI.pm
===================================================================
--- addons/1.3/wxPOS/WXPOS/UI.pm	2014-03-04 13:14:29 UTC (rev 6924)
+++ addons/1.3/wxPOS/WXPOS/UI.pm	2014-03-05 05:09:22 UTC (rev 6925)
@@ -98,15 +98,15 @@
  EVT_MENU($self, $AR_CUSTOMER, sub{$self->_load_module(Contact, Customer)});
  $bar->Append($ar, "&Sales" );
 
-# my $ic = Wx::Menu->new;
-# $ic->Append($IC_PARTS, "&Parts");
-# EVT_MENU($self, $IC_PARTS, sub{$self->_load_module(IC, Parts)});
-# $bar->Append($ic, "&Inventory" );
  my $ap = Wx::Menu->new;
  $ap->Append($AP_INVOICE, "&Purchase");
  EVT_MENU($self, $AP_INVOICE, sub{$self->_load_module('AP', 'Purchase')}); 
  $bar->Append($ap, "&Purchases" );
 
+ my $ic = Wx::Menu->new;
+ $ic->Append($IC_PARTS, "&Stock List");
+ EVT_MENU($self, $IC_PARTS, sub{$self->_load_module('IC', 'Stocklist')});
+ $bar->Append($ic, "&Inventory" );
  $self->SetMenuBar($bar);
  return $self;
 }

Added: addons/1.3/wxPOS/setup/Parts.sql
===================================================================
--- addons/1.3/wxPOS/setup/Parts.sql	                        (rev 0)
+++ addons/1.3/wxPOS/setup/Parts.sql	2014-03-05 05:09:22 UTC (rev 6925)
@@ -0,0 +1,29 @@
+DROP VIEW IF EXISTS stocklist CASCADE;
+
+CREATE VIEW stocklist AS 
+   SELECT p.id, p.partnumber, p.description, p.sellprice, 
+          sum(i.qty) * -1 as onhand
+     FROM parts p
+LEFT JOIN invoice i ON p.id = i.parts_id
+    WHERE not p.obsolete
+ GROUP BY p.id, p.partnumber, p.description, p.sellprice
+;
+
+GRANT SELECT ON stocklist TO PUBLIC;
+
+CREATE OR REPLACE FUNCTION stocklist__search
+(in_partnumber text, in_description text)
+RETURNS SETOF stocklist LANGUAGE SQL AS 
+$$
+SELECT * FROM stocklist 
+ WHERE partnumber like '%' || $1 || '%'
+       AND description like '%' || $2 || '%';
+$$;
+
+CREATE OR REPLACE FUNCTION stocklist__set_price
+(in_id int, in_sellprice numeric)
+RETURNS stocklist LANGUAGE SQL AS
+$$
+UPDATE parts SET sellprice = $2 WHERE id = $1;
+SELECT * FROM stocklist WHERE id = $1;
+$$;

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


------------------------------------------------------------------------------
Subversion Kills Productivity. Get off Subversion & Make the Move to Perforce.
With Perforce, you get hassle-free workflows. Merge that actually works. 
Faster operations. Version large binaries.  Built-in WAN optimization and the
freedom to use Git, Perforce or both. Make the move to Perforce.
http://pubads.g.doubleclick.net/gampad/clk?id=122218951&iu=/4140/ostg.clktrk
_______________________________________________
Ledger-smb-commits mailing list
..hidden..
https://lists.sourceforge.net/lists/listinfo/ledger-smb-commits