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

SF.net SVN: ledger-smb:[5455] trunk



Revision: 5455
          http://ledger-smb.svn.sourceforge.net/ledger-smb/?rev=5455&view=rev
Author:   einhverfr
Date:     2013-01-01 14:51:18 +0000 (Tue, 01 Jan 2013)
Log Message:
-----------
Moved pricegroup search to new framework

Modified Paths:
--------------
    trunk/LedgerSMB/PE.pm
    trunk/LedgerSMB/Report/Inventory/Partsgroups.pm
    trunk/bin/pe.pl
    trunk/sql/Pg-database.sql
    trunk/sql/modules/Goods.sql
    trunk/sql/modules/menu_rebuild.sql

Added Paths:
-----------
    trunk/LedgerSMB/Report/Inventory/Pricegroups.pm
    trunk/UI/Reports/filters/search_partsgroups.html
    trunk/UI/Reports/filters/search_pricegroups.html

Modified: trunk/LedgerSMB/PE.pm
===================================================================
--- trunk/LedgerSMB/PE.pm	2013-01-01 10:24:09 UTC (rev 5454)
+++ trunk/LedgerSMB/PE.pm	2013-01-01 14:51:18 UTC (rev 5455)
@@ -403,68 +403,6 @@
 
 }
 
-=item PE->pricegroups($myconfig, $form);
-
-Populates the list referred to as $form->{item_list} with hashes containing
-details (id and pricegroup (description)) about pricegroups.  All the groups
-are added unless $form->{pricegroup} is set, in which case it will search for
-groups with that description, or $form->{status} is 'orphaned', which limits
-the results to those not related to any customers (partscustomer table).  The
-return value is the number of pricegroups added to the list.
-
-$myconfig is unused.
-
-=cut
-
-sub pricegroups {
-    my ( $self, $myconfig, $form ) = @_;
-
-    my $var;
-
-    my $dbh = $form->{dbh};
-
-    $form->{sort} = "pricegroup" unless $form->{sort};
-    my @a         = qw(pricegroup);
-    my $sortorder = $form->sort_order( ..hidden.. );
-
-    my $query = qq|SELECT g.* FROM pricegroup g|;
-
-    my $where = "1 = 1";
-
-    if ( $form->{pricegroup} ne "" ) {
-        $var = $dbh->quote( $form->like( lc $form->{pricegroup} ) );
-        $where .= " AND lower(pricegroup) LIKE $var";
-    }
-    $query .= qq|
-		WHERE $where ORDER BY $sortorder|;
-
-    if ( $form->{status} eq 'orphaned' ) {
-        $query = qq|
-			SELECT g.*
-			  FROM pricegroup g
-			 WHERE $where
-			       AND g.id NOT IN (SELECT DISTINCT pricegroup_id
-			                          FROM partscustomer
-			                         WHERE pricegroup_id > 0)
-		ORDER BY $sortorder|;
-    }
-
-    $sth = $dbh->prepare($query);
-    $sth->execute || $form->dberror($query);
-
-    my $i = 0;
-    while ( my $ref = $sth->fetchrow_hashref(NAME_lc) ) {
-        push @{ $form->{item_list} }, $ref;
-        $i++;
-    }
-
-    $sth->finish;
-    $dbh->commit;
-
-    $i;
-
-}
-
 =item PE->save_pricegroup($myconfig, $form);
 
 Adds or updates a pricegroup.  If $form->{id} is set, update the pricegroup

Modified: trunk/LedgerSMB/Report/Inventory/Partsgroups.pm
===================================================================
--- trunk/LedgerSMB/Report/Inventory/Partsgroups.pm	2013-01-01 10:24:09 UTC (rev 5454)
+++ trunk/LedgerSMB/Report/Inventory/Partsgroups.pm	2013-01-01 14:51:18 UTC (rev 5455)
@@ -18,13 +18,13 @@
 
 =over
 
-=item pricegroup string
+=item partsgroup string
 
-Prefix match on pricegroup name
+Prefix match on partsgroup name
 
 =cut
 
-has pricegroup => (is => 'ro', isa => 'Str', required => '0');
+has partsgroup => (is => 'ro', isa => 'Str', required => '0');
 
 =back
 

Copied: trunk/LedgerSMB/Report/Inventory/Pricegroups.pm (from rev 5452, trunk/LedgerSMB/Report/Inventory/Partsgroups.pm)
===================================================================
--- trunk/LedgerSMB/Report/Inventory/Pricegroups.pm	                        (rev 0)
+++ trunk/LedgerSMB/Report/Inventory/Pricegroups.pm	2013-01-01 14:51:18 UTC (rev 5455)
@@ -0,0 +1,92 @@
+=head1 NAME
+
+LedgerSMB::Report::Inventory::Pricegroups - Pricegroup search for LedgerSMB
+
+=head1 SYNOPSIS
+
+ my $report = LedgerSMB::Report::Inventory::Pricegroups->new(%$request);
+ $report->render($request);
+
+=cut
+
+package LedgerSMB::Report::Inventory::Pricegroups;
+use Moose;
+extends 'LedgerSMB::Report';
+
+
+=head1 CRITERIAL PROPERTIES
+
+=over
+
+=item pricegroup string
+
+Prefix match on pricegroup name
+
+=cut
+
+has pricegroup => (is => 'ro', isa => 'Str', required => '0');
+
+=back
+
+=head1 INTERNALS
+
+=head2 columns
+
+=over 
+
+=item pricegroup
+
+=back
+
+=cut
+
+sub columns {
+    return [{col_id => 'pricegroup',
+               type => 'href',
+          href_base => 'pe.pl?action=edit&type=pricegroup&id=',
+               name => LedgerSMB::Report::text('Price Group') }];
+}
+
+=head2 header_lines
+
+=over
+
+=item partsgroup
+
+=cut
+
+sub header_lines {
+    return [{name => 'partsgroup',
+             text => LedgerSMB::Report::text('Price Group') }];
+}
+
+=head2 name
+
+Price Groups
+
+=cut
+
+sub name {
+    return LedgerSMB::Report::text('Price Groups');
+}
+
+=head1 METHODS
+
+=head2 run_report
+
+Populates rows
+
+=cut
+
+sub run_report {
+    my ($self) = @_;
+    my @rows = $self->exec_method({funcname => 'pricegroup__search'});
+    $_->{row_id} = $_->{id} for (@rows);
+    $self->rows(..hidden..);
+}
+
+=head1 COPYRIGHT
+
+=cut
+
+__PACKAGE__->meta->make_immutable;

Added: trunk/UI/Reports/filters/search_partsgroups.html
===================================================================
--- trunk/UI/Reports/filters/search_partsgroups.html	                        (rev 0)
+++ trunk/UI/Reports/filters/search_partsgroups.html	2013-01-01 14:51:18 UTC (rev 5455)
@@ -0,0 +1,22 @@
+<?lsmb INCLUDE 'ui-header.html';
+       PROCESS 'elements.html'; ?>
+<body>
+<div class="listtop"><?lsmb text('Search Parts Groups') ?></div>
+<form action="goods.pl" method="GET">
+<div><?lsmb PROCESS input element_data = {
+    name = 'partsgroup'
+   value = partsgroup
+    type = 'text'
+   class = 'name'
+    size = 16
+   label = text('Parts Group') #'
+} ?></div>
+<div><?lsmb PROCESS button element_data = {
+    type = 'submit'
+   class = 'submit'
+    name = 'action'
+    text = text('Search')
+   value = 'search_partsgroups'
+} ?></div>
+<form>
+</body>

Added: trunk/UI/Reports/filters/search_pricegroups.html
===================================================================
--- trunk/UI/Reports/filters/search_pricegroups.html	                        (rev 0)
+++ trunk/UI/Reports/filters/search_pricegroups.html	2013-01-01 14:51:18 UTC (rev 5455)
@@ -0,0 +1,22 @@
+<?lsmb INCLUDE 'ui-header.html';
+       PROCESS 'elements.html'; ?>
+<body>
+<div class="listtop"><?lsmb text('Search Price Groups') ?></div>
+<form action="goods.pl" method="GET">
+<div><?lsmb PROCESS input element_data = {
+    name = 'pricegroup'
+   value = pricegroup
+    type = 'text'
+   class = 'name'
+    size = 16
+   label = text('Price Group') #'
+} ?></div>
+<div><?lsmb PROCESS button element_data = {
+    type = 'submit'
+   class = 'submit'
+    name = 'action'
+    text = text('Search')
+   value = 'search_pricegroups'
+} ?></div>
+<form>
+</body>

Modified: trunk/bin/pe.pl
===================================================================
--- trunk/bin/pe.pl	2013-01-01 10:24:09 UTC (rev 5454)
+++ trunk/bin/pe.pl	2013-01-01 14:51:18 UTC (rev 5455)
@@ -52,179 +52,6 @@
       if $form->{id};
 }
 
-sub prepare_project {
-
-    $form->{vc} = 'customer';
-
-    PE->get_project( \%myconfig, \%$form );
-
-    $form->{title} =
-      ( $form->{id} )
-      ? $locale->text('Edit Project')
-      : $locale->text('Add Project');
-
-    $form->{"old$form->{vc}"} =
-      qq|$form->{"$form->{vc}"}--$form->{"$form->{vc}_id"}|;
-
-    if ( @{ $form->{"all_$form->{vc}"} } ) {
-        $form->{"$form->{vc}"} =
-          qq|$form->{"$form->{vc}"}--$form->{"$form->{vc}_id"}|;
-        $form->{"select$form->{vc}"} = qq|<option>\n|;
-        for ( @{ $form->{"all_$form->{vc}"} } ) {
-            $form->{"select$form->{vc}"} .=
-              qq|<option value="$_->{name}--$_->{id}">$_->{name}\n|;
-        }
-    }
-
-}
-
-sub search {
-
-    # accounting years
-    $form->all_years( \%myconfig );
-
-    if ( @{ $form->{all_years} } ) {
-        $form->{selectaccountingyear} = "<option>\n";
-        for ( @{ $form->{all_years} } ) {
-            $form->{selectaccountingyear} .= qq|<option>$_\n|;
-        }
-
-        $form->{selectaccountingmonth} = "<option>\n";
-        for ( sort keys %{ $form->{all_month} } ) {
-            $form->{selectaccountingmonth} .=
-              qq|<option value=$_>|
-              . $locale->text( $form->{all_month}{$_} ) . qq|\n|;
-        }
-
-        $fromto = qq|
- 	<tr>
-	  <th align=right>| . $locale->text('Startdate') . qq|</th>
-	  <td>|
-          . $locale->text('From')
-          . qq| <input class="date" name=startdatefrom size=11 title="($myconfig{'dateformat'})">|
-          . $locale->text('To') . qq|
-	  <input class="date" name=startdateto size=11 title="($myconfig{'dateformat'})"></td>
-	</tr>
-|;
-
-        $selectperiod = qq|
-        <tr>
-	  <th align=right>| . $locale->text('Period') . qq|</th>
-	  <td colspan=3>
-	  <select name=month>$form->{selectaccountingmonth}</select>
-	  <select name=year>$form->{selectaccountingyear}</select>
-	  <input name=interval class=radio type=radio value=0 checked>&nbsp;|
-          . $locale->text('Current') . qq|
-	  <input name=interval class=radio type=radio value=1>&nbsp;|
-          . $locale->text('Month') . qq|
-	  <input name=interval class=radio type=radio value=3>&nbsp;|
-          . $locale->text('Quarter') . qq|
-	  <input name=interval class=radio type=radio value=12>&nbsp;|
-          . $locale->text('Year') . qq|
-	  </td>
-	</tr>
-|;
-    }
-
-    $orphaned = qq|
-	  <input name=status class=radio type=radio value=orphaned>&nbsp;|
-      . $locale->text('Orphaned');
-
-    if ( $form->{type} eq 'partsgroup' ) {
-        $report        = "partsgroup_report";
-        $sort          = 'partsgroup';
-        $form->{title} = $locale->text('Groups');
-
-        $fromto       = "";
-        $selectperiod = "";
-        $number       = qq|
-	<tr>
-	  <th align=right width=1%>| . $locale->text('Group') . qq|</th>
-	  <td><input name=partsgroup size=20></td>
-	</tr>
-|;
-    }
-
-    if ( $form->{type} eq 'pricegroup' ) {
-        $report        = "pricegroup_report";
-        $sort          = 'pricegroup';
-        $form->{title} = $locale->text('Pricegroups');
-
-        $fromto       = "";
-        $selectperiod = "";
-        $number       = qq|
-	<tr>
-	  <th align=right width=1%>| . $locale->text('Pricegroup') . qq|</th>
-	  <td><input name=pricegroup size=20></td>
-	</tr>
-|;
-    }
-
-    $form->header;
-
-    print qq|
-<body>
-
-<form method=post action=$form->{script}>
-
-<input type=hidden name=sort value=$sort>
-<input type=hidden name=type value=$form->{type}>
-
-<table width=100%>
-  <tr>
-    <th class=listtop>$form->{title}</th>
-  </tr>
-  <tr height="5"></tr>
-  <tr>
-    <td>
-      <table width=100%>
-        $number
-	$fromto
-	$selectperiod
-	<tr>
-	  <td></td>
-	  <td><input name=status class=radio type=radio value=all checked>&nbsp;|
-      . $locale->text('All') . qq|
-	  <input name=status class=radio type=radio value=active>&nbsp;|
-      . $locale->text('Active') . qq|
-	  <input name=status class=radio type=radio value=inactive>&nbsp;|
-      . $locale->text('Inactive') . qq|
-	  $orphaned</td>
-	</tr>
-      </table>
-    </td>
-  </tr>
-  <tr>
-    <td><hr size=3 noshade></td>
-  </tr>
-</table>
-
-<input type=hidden name=nextsub value=$report>
-|;
-
-    $form->hide_form(qw(path login sessionid title));
-
-    print qq|
-<button class="submit" type="submit" name="action" value="continue">|
-      . $locale->text('Continue')
-      . qq|</button>
-</form>
-|;
-
-    if ( $form->{lynx} ) {
-        require "bin/menu.pl";
-        &menubar;
-    }
-
-    print qq|
- 
-</body>
-</html>
-|;
-
-}
-
-
 sub save {
 
     if ( $form->{translation} ) {
@@ -355,135 +182,6 @@
 
 }
 
-sub pricegroup_report {
-
-    $form->{pricegroup} = $form->unescape( $form->{pricegroup} );
-    PE->pricegroups( \%myconfig, \%$form );
-
-    $href =
-"$form->{script}?action=pricegroup_report&direction=$form->{direction}&oldsort=$form->{oldsort}&type=$form->{type}&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}&status=$form->{status}";
-
-    $form->sort_order();
-
-    $callback =
-"$form->{script}?action=pricegroup_report&direction=$form->{direction}&oldsort=$form->{oldsort}&type=$form->{type}&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}&status=$form->{status}";
-
-    if ( $form->{status} eq 'all' ) {
-        $option = $locale->text('All');
-    }
-    if ( $form->{status} eq 'orphaned' ) {
-        $option .= $locale->text('Orphaned');
-    }
-    if ( $form->{pricegroup} ) {
-        $callback .= "&pricegroup=$form->{pricegroup}";
-        $option .=
-          "\n<br>" . $locale->text('Pricegroup') . " : $form->{pricegroup}";
-    }
-
-    @column_index = $form->sort_columns(qw(pricegroup));
-
-    $column_header{pricegroup} =
-        qq|<th><a class=listheading href=$href&sort=pricegroup width=90%>|
-      . $locale->text('Pricegroup')
-      . qq|</th>|;
-
-    $form->{title} = $locale->text('Pricegroups');
-
-    $form->header;
-
-    print qq|
-<body>
-
-<table width=100%>
-  <tr>
-    <th class=listtop>$form->{title}</th>
-  </tr>
-  <tr height="5"></tr>
-  <tr>
-    <td>$option</td>
-  </tr>
-  <tr>
-    <td>
-      <table width=100%>
-	<tr class=listheading>
-|;
-
-    for (@column_index) { print "$column_header{$_}\n" }
-
-    print qq|
-        </tr>
-|;
-
-    # escape callback
-    $form->{callback} = $callback;
-
-    # escape callback for href
-    $callback = $form->escape($callback);
-
-    foreach $ref ( @{ $form->{item_list} } ) {
-
-        $i++;
-        $i %= 2;
-
-        print qq|
-        <tr valign=top class=listrow$i>
-|;
-
-        $column_data{pricegroup} =
-qq|<td><a href=$form->{script}?action=edit&type=$form->{type}&status=$form->{status}&id=$ref->{id}&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}&callback=$callback>$ref->{pricegroup}</td>|;
-        for (@column_index) { print "$column_data{$_}\n" }
-
-        print "
-        </tr>
-";
-    }
-
-    $i = 1;
-    if ( $myconfig{acs} !~ /Goods \& Services--Goods \& Services/ ) {
-        $button{'Goods & Services--Add Pricegroup'}{code} =
-qq|<button class="submit" type="submit" name="action" value="add_pricegroup">|
-          . $locale->text('Add Pricegroup')
-          . qq|</button> |;
-        $button{'Goods & Services--Add Pricegroup'}{order} = $i++;
-
-        foreach $item ( split /;/, $myconfig{acs} ) {
-            delete $button{$item};
-        }
-    }
-
-    print qq|
-      </table>
-    </td>
-  </tr>
-  <tr>
-    <td><hr size=3 noshade></td>
-  </tr>
-</table>
-
-<br>
-<form method=post action=$form->{script}>
-|;
-
-    $form->hide_form(qw(callback type path login sessionid));
-
-    foreach $item ( sort { $a->{order} <=> $b->{order} } %button ) {
-        print $item->{code};
-    }
-
-    if ( $form->{lynx} ) {
-        require "bin/menu.pl";
-        &menubar;
-    }
-
-    print qq|
-  </form>
-
-</body>
-</html>
-|;
-
-}
-
 sub pricegroup_header {
 
     $form->{title} = $locale->text( ucfirst $form->{action} . " Pricegroup" );

Modified: trunk/sql/Pg-database.sql
===================================================================
--- trunk/sql/Pg-database.sql	2013-01-01 10:24:09 UTC (rev 5454)
+++ trunk/sql/Pg-database.sql	2013-01-01 14:51:18 UTC (rev 5455)
@@ -3053,13 +3053,12 @@
 85	menu	1	204
 88	module	ic.pl	211
 88	action	requirements	212
-92	module	pe.pl	224
-92	action	search	223
 95	menu	1	232
 96	module	pe.pl	233
 96	action	translation	234
 96	translation	description	235
 91	action	start_report	220
+92	action	start_report	223
 97	module	pe.pl	236
 97	action	translation	237
 97	translation	partsgroup	238
@@ -3429,7 +3428,6 @@
 248	type	sic	667
 83	type	pricegroup	200
 82	type	partsgroup	197
-92	type	pricegroup	225
 203	batch_type	receipt	567
 250	menu	1	669
 7	module_name	gl	671
@@ -3495,6 +3493,8 @@
 86	module	goods.pl	205
 91	module	reports.pl	221
 91	report_name	search_partsgroups	222
+92	module	reports.pl	224
+92	report_name	search_pricegroups	225
 \.
 
 --

Modified: trunk/sql/modules/Goods.sql
===================================================================
--- trunk/sql/modules/Goods.sql	2013-01-01 10:24:09 UTC (rev 5454)
+++ trunk/sql/modules/Goods.sql	2013-01-01 14:51:18 UTC (rev 5455)
@@ -125,7 +125,13 @@
   SELECT * FROM partsgroup 
    WHERE $1 is null or partsgroup ilike $1 || '%'
 ORDER BY partsgroup;
+$$;
 
+CREATE OR REPLACE FUNCTION pricegroup__search(in_pricegroup text)
+RETURNS SETOF pricegroup LANGUAGE SQL STABLE AS $$
+  SELECT * FROM pricegroup
+   WHERE $1 IS NULL OR pricegroup ilike $1 || '%'
+ORDER BY pricegroup;
 $$;
 
 

Modified: trunk/sql/modules/menu_rebuild.sql
===================================================================
--- trunk/sql/modules/menu_rebuild.sql	2013-01-01 10:24:09 UTC (rev 5454)
+++ trunk/sql/modules/menu_rebuild.sql	2013-01-01 14:51:18 UTC (rev 5455)
@@ -206,11 +206,6 @@
 
 
 --
--- Name: menu_acl_id_seq; Type: SEQUENCE SET; Schema: public; Owner: postgres
---
-
-
---
 -- Data for Name: menu_attribute; Type: TABLE DATA; Schema: public; Owner: postgres
 --
 
@@ -362,13 +357,12 @@
 85	menu	1	204
 88	module	ic.pl	211
 88	action	requirements	212
-92	module	pe.pl	224
-92	action	search	223
 95	menu	1	232
 96	module	pe.pl	233
 96	action	translation	234
 96	translation	description	235
 91	action	start_report	220
+92	action	start_report	223
 97	module	pe.pl	236
 97	action	translation	237
 97	translation	partsgroup	238
@@ -738,7 +732,6 @@
 248	type	sic	667
 83	type	pricegroup	200
 82	type	partsgroup	197
-92	type	pricegroup	225
 203	batch_type	receipt	567
 250	menu	1	669
 7	module_name	gl	671
@@ -804,6 +797,8 @@
 86	module	goods.pl	205
 91	module	reports.pl	221
 91	report_name	search_partsgroups	222
+92	module	reports.pl	224
+92	report_name	search_pricegroups	225
 \.
 
 
@@ -1102,36 +1097,6 @@
 
 
 --
--- Name: menu_acl; Type: ACL; Schema: public; Owner: postgres
---
-
-REVOKE ALL ON TABLE menu_acl FROM PUBLIC;
-REVOKE ALL ON TABLE menu_acl FROM postgres;
-GRANT ALL ON TABLE menu_acl TO postgres;
-GRANT SELECT ON TABLE menu_acl TO PUBLIC;
-
-
---
--- Name: menu_attribute; Type: ACL; Schema: public; Owner: postgres
---
-
-REVOKE ALL ON TABLE menu_attribute FROM PUBLIC;
-REVOKE ALL ON TABLE menu_attribute FROM postgres;
-GRANT ALL ON TABLE menu_attribute TO postgres;
-GRANT SELECT ON TABLE menu_attribute TO PUBLIC;
-
-
---
--- Name: menu_node; Type: ACL; Schema: public; Owner: postgres
---
-
-REVOKE ALL ON TABLE menu_node FROM PUBLIC;
-REVOKE ALL ON TABLE menu_node FROM postgres;
-GRANT ALL ON TABLE menu_node TO postgres;
-GRANT SELECT ON TABLE menu_node TO PUBLIC;
-
-
---
 -- PostgreSQL database dump complete
 --
 

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