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

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



Revision: 4912
          http://ledger-smb.svn.sourceforge.net/ledger-smb/?rev=4912&view=rev
Author:   einhverfr
Date:     2012-06-18 12:06:54 +0000 (Mon, 18 Jun 2012)
Log Message:
-----------
A few fixes to defaults screen

Modified Paths:
--------------
    trunk/LedgerSMB/AM.pm
    trunk/bin/am.pl

Added Paths:
-----------
    trunk/LedgerSMB/Scripts/configuration.pl

Modified: trunk/LedgerSMB/AM.pm
===================================================================
--- trunk/LedgerSMB/AM.pm	2012-06-18 11:58:25 UTC (rev 4911)
+++ trunk/LedgerSMB/AM.pm	2012-06-18 12:06:54 UTC (rev 4912)
@@ -1351,206 +1351,6 @@
 
 }
 
-=item AM->save_defaults($myconfig, $form, ..hidden..);
-
-Sets the values in the defaults table to values derived from $form.  glnumber,
-sinumber, vinumber, sonumber, ponumber, sqnumber, rfqnumber, partnumber,
-employeenumber, customernumber, vendornumber, projectnumber, yearend, curr,
-weightunit, and businessnumber are taken directly from the $form value with
-the corresponding name.  inventory_accno_id is the id of the account with the
-number specified in $form->{IC}.  In a similar manner, income_accno_id and
-$form->{IC_income}, expense_accno_id and $form->{IC_expense}, fxgain_accno_id
-and $form->{FX_gain}, and fxloss_accno_id and $form->{FX_loss} are related. 
-
-Stores the templates directory for a specific company on defaults table.
-
..hidden.. identifies the list of values to be stored in defaults.  If not 
-provided, a default list is used.
-
-=cut
-
-sub save_defaults {
-
-    my ( $self, $myconfig, $form, $defaults) = @_;
-
-    for (qw(IC IC_income IC_expense FX_gain FX_loss)) {
-        ( $form->{$_} ) = split /--/, $form->{$_};
-    }
-
-    my @a;
-    $form->{curr} =~ s/ //g;
-    for ( split /:/, $form->{curr} ) { push( @a, uc pack "A3", $_ ) if $_ }
-    $form->{curr} = join ':', @a;
-    # connect to database
-    my $dbh = $form->{dbh};
-    # save defaults
-#    $sth_plain = $dbh->prepare( "
-#		UPDATE defaults SET value = ? WHERE setting_key = ?" );
-    $sth_accno = $dbh->prepare(
-        qq|
-		UPDATE defaults
-                   SET value = (SELECT id
-                                               FROM chart
-                                              WHERE accno = ?)
-		 WHERE setting_key = ?|
-    );
-    my %translation = (
-        inventory_accno_id => 'IC',
-        income_accno_id    => 'IC_income',
-        expense_accno_id   => 'IC_expense',
-        fxgain_accno_id    => 'FX_gain',
-        fxloss_accno_id    => 'FX_loss'
-    );
-    if (..hidden..){
-       $defaults = qw(inventory_accno_id income_accno_id expense_accno_id
-                      fxgain_accno_id fxloss_accno_id glnumber sinumber vinumber
-                      sonumber ponumber sqnumber rfqnumber partnumber 
-                      employeenumber customernumber vendornumber projectnumber 
-                      yearend curr weightunit businessnumber default_country 
-                      check_prefix password_duration templates vclimit template_images)
-    }
-    for (@$defaults)
-    {
-        my $val = $form->{$_};
-        if ( $translation{$_} ) {
-            $val = $form->{ $translation{$_} };
-        }
-        if ( $_ =~ /accno/ ) {
-            $sth_accno->execute( $val, $_ )
-              || $form->dberror("Saving $_");
-        }
-        else {
-				    my $found=0;
-				    my $sth_defcheck=$dbh->prepare("select count(*) from defaults where setting_key='$_';") || $form->dberror("Select defaults $_");
-				    $sth_defcheck->execute() || $form->dberror("execute defaults $_");
-			            while(my $found1=$sth_defcheck->fetchrow()){$found=$found1;}
-				    
-				  if($found)
-				  {
-					$dbh->do("update defaults set value=" . $dbh->quote($val) . " where setting_key='$_';");
-				  }
-				  else
-				  {
-					$dbh->do("insert into defaults(value,setting_key) values( " . $dbh->quote($val) . ",'$_');"); 
-				  }
-
-        }
-
-    }
-    my $rc = $dbh->commit;
-
-    $rc;
-
-}
-
-=item AM->defaultaccounts($myconfig, $form);
-
-Retrieves the numbers of default accounts and sets $form->{defaults}{$key} to
-the appropriate account numbers, where $key can be 'IC', 'IC_income', 'IC_sale',
-'IC_expense', 'IC_cogs', 'FX_gain', and 'FX_loss'.
-
-Sets the hashes refered to as $form->{accno}{IC_${type}}{$accno} to contain the
-id and description of all accounts with IC elements in their link fields.  The
-possible types are all the IC_* values with IC_cogs merged into IC_expense and
-IC_sale merged with IC_income.
-
-Fills the hashes referred to as $form->{accno}{FX_(gain|loss)} with the id and
-description of all income and expense accounts, keyed on the account number.
-
-$myconfig is unused.
-
-=cut
-
-sub defaultaccounts {
-
-    my ( $self, $myconfig, $form ) = @_;
-
-    # connect to database
-    my $dbh = $form->{dbh};
-
-    # get defaults from defaults table
-    my $query = qq|
-		SELECT setting_key, value FROM defaults
-		 WHERE setting_key LIKE ?|;
-    my $sth = $dbh->prepare($query);
-    $sth->execute('%accno_id') || $form->dberror($query);
-
-    my $ref;
-    while ( $ref = $sth->fetchrow_hashref(NAME_lc) ) {
-        $form->{ $ref->{setting_key} } = $ref->{value};
-    }
-
-    $form->{defaults}{IC}         = $form->{inventory_accno_id};
-    $form->{defaults}{IC_income}  = $form->{income_accno_id};
-    $form->{defaults}{IC_sale}    = $form->{income_accno_id};
-    $form->{defaults}{IC_expense} = $form->{expense_accno_id};
-    $form->{defaults}{IC_cogs}    = $form->{expense_accno_id};
-    $form->{defaults}{FX_gain}    = $form->{fxgain_accno_id};
-    $form->{defaults}{FX_loss}    = $form->{fxloss_accno_id};
-
-    $sth->finish;
-
-    $query = qq|
-		SELECT id, accno, description, link
-		  FROM chart
-		 WHERE link LIKE '%IC%'
-		 ORDER BY accno|;
-
-    $sth = $dbh->prepare($query);
-    $sth->execute || $form->dberror($query);
-
-    my $nkey;
-    while ( $ref = $sth->fetchrow_hashref(NAME_lc) ) {
-        foreach my $key ( split( /:/, $ref->{link} ) ) {
-            if ( $key =~ /IC/ ) {
-                $nkey = $key;
-
-                if ( $key =~ /cogs/ ) {
-                    $nkey = "IC_expense";
-                }
-
-                if ( $key =~ /sale/ ) {
-                    $nkey = "IC_income";
-                }
-
-                %{ $form->{accno}{$nkey}{ $ref->{accno} } } = (
-                    id          => $ref->{id},
-                    description => $ref->{description}
-                );
-            }
-        }
-    }
-
-    $sth->finish;
-
-    $query = qq|
-		    SELECT id, accno, description
-		      FROM chart
-		     WHERE (category = 'I' OR category = 'E')
-		           AND charttype = 'A'
-		  ORDER BY accno|;
-
-    $sth = $dbh->prepare($query);
-    $sth->execute || $form->dberror($query);
-
-    while ( my $ref = $sth->fetchrow_hashref(NAME_lc) ) {
-        %{ $form->{accno}{FX_gain}{ $ref->{accno} } } = (
-            id          => $ref->{id},
-            description => $ref->{description}
-        );
-
-        %{ $form->{accno}{FX_loss}{ $ref->{accno} } } = (
-            id          => $ref->{id},
-            description => $ref->{description}
-        );
-    }
-
-    $sth->finish;
-
-    $dbh->commit;
-
-}
-
 =item AM->taxes($myconfig, $form);
 
 Retrieve details about all taxes in the database.  $form->{taxrates} refers to a
@@ -1920,47 +1720,6 @@
 
 }
 
-=item AM->get_all_defaults($form);
-
-Retrieves all settings from defaults and sets the appropriate $form values.
-Also runs AM->defaultaccounts.
-
-=cut
-
-sub get_all_defaults {
-    my ( $self, $form ) = @_;
-    my $dbh   = $form->{dbh};
-    my $query = "select setting_key, value FROM defaults";
-    $sth = $dbh->prepare($query);
-    $sth->execute;
-    while ( ( $skey, $value ) = $sth->fetchrow_array() ) {
-        $form->{$skey} = $value;
-    }
-    $sth->finish;
-    $query = "select id, name from country order by name";
-    $sth = $dbh->prepare($query);
-    $sth->execute;
-    $form->{countries} = [];
-    while ($ref = $sth->fetchrow_hashref('NAME_lc')) {
-        push @{$form->{countries}}, $ref;
-    }
-    $sth->finish;
-    #HV do not know if i can use 'sub language' here which fills $form->{ALL}
-    $query = "select code,description from language order by code";
-    $sth = $dbh->prepare($query);
-    $sth->execute;
-    $form->{languages} = [];
-    while ($ref = $sth->fetchrow_hashref('NAME_lc')) {
-        push @{$form->{languages}}, $ref;
-    }
-    $sth->finish;
-
-    $self->defaultaccounts( undef, $form );
-    $dbh->commit;
-    my $dirname = "./templates";
-    my $subdircount = 0;
-}
-
 =item AM->get_templates_directories;
 
 This functions gets all the directories from $LedgerSMB::Sysconfig::templates to list all the possible

Added: trunk/LedgerSMB/Scripts/configuration.pl
===================================================================
--- trunk/LedgerSMB/Scripts/configuration.pl	                        (rev 0)
+++ trunk/LedgerSMB/Scripts/configuration.pl	2012-06-18 12:06:54 UTC (rev 4912)
@@ -0,0 +1,148 @@
+=head1 NAME
+
+LedgerSMB::Scripts::configuration - Configuration Workflows for LedgerSMB
+
+=head1 SYNPOPSIS
+
+LedgerSMB::Scripts::configuration->can('action')->($request);
+
+=cut
+package LedgerSMB::Scripts::configuration;
+use LedgerSMB::Setting;
+use LedgerSMB::AM; # To be removed, only for template directories right now
+use strict;
+use warnings;
+
+our @default_textboxes = (
+   { name => 'glnumber', label => $locale->text('GL Reference Number') },
+   { name => 'sinumber', 
+      label => $locale->text('Sales Invoice/AR Transaction Number'), },
+   { name => 'vclimit', label => $locale->text('Max per dropdown') },
+   { name => 'sonumber', label => $locale->text('Sales Order Number') },
+   { name => 'vinumber' , 
+    label => $locale->text('Vendor Invoice/AP Transaction Number')},
+   { name => 'sqnumber', label => $locale->text('Sales Quotation Number') },
+   { name => 'rfqnumber', label => $locale->text('RFQ Number') },
+   { name => 'partnumber', label => $locale->text('Part Number') },
+   { name => 'projectnumber', label => $locale->text('Job/Project Number') },
+   { name => 'employeenumber', label => $locale->text('Employee Number') },
+   { name => 'customernumber', label => $locale->text('Customer Number') },
+   { name => 'vendornumber', label => $locale->text('Vendor Number') },
+   { name => 'check_prefix', label => $locale->text('Check Prefix') },
+   { name => 'password_duration', label => $locale->text('Password Duration') },
+   { name => 'default_email_to', label => $locale->text('Default Email To') },
+   { name => 'default_email_cc', label => $locale->text('Default Email CC') },
+   { name => 'default_email_bcc', label => $locale->text('Default Email BCC') },
+   { name => 'default_email_from', 
+     label => $locale->text('Default Email From') },
+   { name => 'company_name', label => $locale->text('Company Name') },
+   { name => 'company_address', label => $locale->text('Company Address') },
+   { name => 'company_phone', label => $locale->text('Company Phone') },
+   { name => 'company_fax', label => $locale->text('Company Fax') },
+   { name => 'company_sales_tax_id', 
+                             label =>  $locale->text('Company Sales Tax ID') },
+   { name => 'company_license_number',
+                           label =>  $locale->text('Company License Number') },
+);
+
+our @default_others = qw(businessnumber weightunit separate_duties default_language
+                        inventory_accno_id income_accno_id expense_accno_id 
+                        fxgain_accno_id fxloss_accno_id default_country 
+                        templates curr template_images);
+
+
+
+=head1 METHODS/ACTIONS
+
+=over
+
+=item defaults_screen
+
+Shows the defaults screen
+
+=cut
+
+sub defaults_screen{
+    my $request = @_;
+    $setting_handle = LedgerSMB::Setting->new({base => $request});
+    my @defaults = @default_others;
+    for $tb (@default_textboxes){
+        push @defaults, $tb->{name};
+    }
+    for my $skey (@defaults){
+        $request->{$skey} = $setting_handle->get($skey);
+    }
+    my @country_list = $request->call_procedure(
+                     procname => 'location_list_country'
+    );
+    my @language_code_list =
+             $request->call_procedure(procname=> 'person__list_languages');
+
+
+    my %selects = (
+        'fxloss_accno_id' => {name => 'fxloss_accno_id', 
+                           options => $setting_handle->accounts_by_link('FX_loss')},
+        'fxgain_accno_id' => {name => 'fxgain_accno_id', 
+                           options => $setting_handle->accounts_by_link('FX_gain')},
+        'expense_accno_id' => {name => 'expense_accno_id', 
+                            options => $setting_handle->accounts_by_link('IC_expense')},
+        'income_accno_id' => {name => 'income_accno_id',
+                           options => $setting_handle->accounts_by_link('IC_income')},
+        'inventory_accno_id' => {name => 'inventory_accno_id', 
+                     options => $setting_handle->accounts_by_link('IC')},
+	'default_country' => {name   => 'default_country', 
+			     options => ..hidden..,
+			     default_values => [$request->{'default_country'}],
+			     text_attr => 'name',
+			     value_attr => 'id',
+		},
+	'default_language' => {name   => 'default_language', 
+			     options => ..hidden..,
+			     default_values => [$request->{'default_language'}],
+			     text_attr => 'description',
+			     value_attr => 'code',
+		},
+	'templates'       => {name => 'templates',
+                           options => AM->get_template_directories }	
+        );
+    my $template = LedgerSMB::Template->new_UI(
+        user => \%myconfig, 
+        locale => $locale,
+        template => 'am-defaults');
+    $template->render({
+        form => $form,
+	hiddens => \%hiddens,
+	selects => \%selects,
+        default_textboxes => ..hidden..,
+    });
+}
+
+=item save_defaults
+
+Saves settings from the defaults screen
+
+=cut
+
+sub save_defaults {
+    my $request = @_;
+    $setting_handle = LedgerSMB::Setting->new({base => $request});
+    my @defaults = @default_others;
+    for $tb (@default_textboxes){
+        push @defaults, $tb->{name};
+    }
+    for my $skey (@defaults){
+        $request->{$skey} =~ s/--.*$// if $skey =~ /accno_id/;
+        $setting_handle->set($skey, $request->{$skey});
+    }
+    default_screen($request);
+}
+
+=head1 COPYRIGHT
+
+Copyright (C) 2012 The LedgerSMB Core Team.  This file may be reused under the
+conditions of the GNU GPL v2 or at your option any later version.  Please see
+the accompanying LICENSE.TXT for more information.
+
+=cut
+
+1;

Modified: trunk/bin/am.pl
===================================================================
--- trunk/bin/am.pl	2012-06-18 11:58:25 UTC (rev 4911)
+++ trunk/bin/am.pl	2012-06-18 12:06:54 UTC (rev 4912)
@@ -1130,72 +1130,6 @@
 
 }
 
-sub defaults {
-    # get defaults for account numbers and last numbers
-    AM->get_all_defaults( \%$form );
-    my %selects = (
-        'fxloss_accno_id' => {name => 'fxloss_accno_id', options => []},
-        'fxgain_accno_id' => {name => 'fxgain_accno_id', options => []},
-        'expense_accno_id' => {name => 'expense_accno_id', options => []},
-        'income_accno_id' => {name => 'income_accno_id', options => []},
-        'inventory_accno_id' => {name => 'inventory_accno_id', options => []},
-	'default_country' => {name   => 'default_country', 
-			     options => $form->{countries},
-			     default_values => [$form->{'default_country'}],
-			     text_attr => 'name',
-			     value_attr => 'id',
-		},
-	'default_language' => {name   => 'default_language', 
-			     options => $form->{languages},
-			     default_values => [$form->{'default_language'}],
-			     text_attr => 'description',
-			     value_attr => 'code',
-		},
-	'templates'       => {name => 'templates', options => []}	
-        );
-    foreach $key ( keys %{ $form->{accno} } ) {
-	print STDERR "$key\n";
-        foreach $accno ( sort keys %{ $form->{accno}{$key} } ) {
-            push @{$selects{$key}{options}}, {
-                text => "$accno--$form->{accno}{$key}{$accno}{description}",
-                value => "$accno--$form->{accno}{$key}{$accno}{description}",
-                };
-            $selects{$key}{default_values} = ["$accno--$form->{accno}{$key}{$accno}{description}"] if
-                ($form->{defaults}{$key} == $form->{accno}{$key}{$accno}{id});
-            print STDERR "$key $accno--$form->{accno}{$key}{$accno}{description}\n" if
-                ($form->{defaults}{$key} == $form->{accno}{$key}{$accno}{id});
-        }
-    }
-    for (qw(accno defaults)) { delete $form->{$_} }
-##SC: temporary commenting out
-##    if ( $form->{lynx} ) {
-##        require "bin/menu.pl";
-##        &menubar;
-##    }
-    # get_templates_directories the NON-UI templates options - David Mora
-    AM->get_templates_directories( \%$form );
-    foreach my $ref (@{$form->{templates_directories}}) {
-      push @{$selects{templates}{options}}, {text => $ref,value => $ref};
-    } 
-    $selects{templates}{default_values} = $form->{templates};
-    my %hiddens = (
-        path => $form->{path},
-        login => $form->{login},
-        sessionid => $form->{sessionid},
-        type => 'defaults',
-        );
-    my $template = LedgerSMB::Template->new_UI(
-        user => \%myconfig, 
-        locale => $locale,
-        template => 'am-defaults');
-    $template->render({
-        form => $form,
-	hiddens => \%hiddens,
-	selects => \%selects,
-        default_textboxes => ..hidden..,
-    });
-}
-
 sub taxes {
 
     # get tax account numbers
@@ -1460,26 +1394,6 @@
     });
 }
 
-sub save_defaults {
-    my @defaults;
-    if ($form->{password_duration} =~ /\D/){
-        $form->error(
-           $locale->text('Password duration must be an integer')
-        );
-    }
-    for (@default_textboxes){
-       push @defaults, $_->{name};
-    } 
-    push @defaults, @default_others;
-    if ( AM->save_defaults( \%myconfig, $form, ..hidden..) ) {
-        $form->redirect( $locale->text('Defaults saved!') );
-    }
-    else {
-        $form->error( $locale->text('Cannot save defaults!') );
-    }
-
-}
-
 sub save_taxes {
 
     if ( AM->save_taxes( \%myconfig, \%$form ) ) {

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