Dialogbuchen - Abteilung nutzt immer L.select_tag als Dropdown
authorG. Richardson <information@kivitendo-premium.de>
Fri, 23 Dec 2016 07:28:47 +0000 (08:28 +0100)
committerG. Richardson <information@kivitendo-premium.de>
Tue, 27 Dec 2016 12:02:24 +0000 (13:02 +0100)
SL/GL.pm
bin/mozilla/gl.pl
templates/webpages/gl/form_header.html
templates/webpages/gl/search.html

index 20d469a..09fc2f0 100644 (file)
--- a/SL/GL.pm
+++ b/SL/GL.pm
@@ -113,8 +113,6 @@ sub _post_transaction {
     do_query($form, $dbh, $query, @values);
   }
 
-  my ($null, $department_id) = split(/--/, $form->{department});
-
   $form->{ob_transaction} *= 1;
   $form->{cb_transaction} *= 1;
 
@@ -126,7 +124,7 @@ sub _post_transaction {
        WHERE id = ?|;
 
   @values = ($form->{reference}, $form->{description}, $form->{notes},
-             conv_date($form->{transdate}), conv_i($department_id), $form->{taxincluded} ? 't' : 'f',
+             conv_date($form->{transdate}), conv_i($form->{department_id}), $form->{taxincluded} ? 't' : 'f',
              $form->{storno} ? 't' : 'f', conv_i($form->{storno_id}), $form->{ob_transaction} ? 't' : 'f', $form->{cb_transaction} ? 't' : 'f',
              conv_i($form->{id}));
   do_query($form, $dbh, $query, @values);
@@ -233,14 +231,13 @@ sub all_transactions {
     push(@apvalues, like($form->{reference}));
   }
 
-  if ($form->{department}) {
-    my ($null, $department) = split /--/, $form->{department};
+  if ($form->{department_id}) {
     $glwhere .= qq| AND g.department_id = ?|;
     $arwhere .= qq| AND a.department_id = ?|;
     $apwhere .= qq| AND a.department_id = ?|;
-    push(@glvalues, $department);
-    push(@arvalues, $department);
-    push(@apvalues, $department);
+    push(@glvalues, $form->{department_id});
+    push(@arvalues, $form->{department_id});
+    push(@apvalues, $form->{department_id});
   }
 
   if ($form->{source}) {
@@ -639,7 +636,8 @@ sub transaction {
   if ($form->{id}) {
     $query =
       qq|SELECT g.reference, g.description, g.notes, g.transdate, g.storno, g.storno_id,
-           d.description AS department, e.name AS employee, g.taxincluded, g.gldate,
+           g.department_id, d.description AS department,
+           e.name AS employee, g.taxincluded, g.gldate,
          g.ob_transaction, g.cb_transaction
          FROM gl g
          LEFT JOIN department d ON (d.id = g.department_id)
index 7237a59..2c203d3 100644 (file)
@@ -99,16 +99,7 @@ sub add {
   $form->{credit} = 0;
   $form->{tax}    = 0;
 
-  # departments
-  $form->all_departments(\%myconfig);
-  if (@{ $form->{all_departments} || [] }) {
-    $form->{selectdepartment} = "<option>\n";
-
-    map {
-      $form->{selectdepartment} .=
-        "<option>$_->{description}--$_->{id}\n"
-    } (@{ $form->{all_departments} || [] });
-  }
+  $::form->{ALL_DEPARTMENTS} = SL::DB::Manager::Department->get_all;
 
   $form->{show_details} = $myconfig{show_form_details} unless defined $form->{show_details};
 
@@ -129,16 +120,7 @@ sub prepare_transaction {
 
   $form->{amount} = $form->format_amount(\%myconfig, $form->{amount}, 2);
 
-  # departments
-  $form->all_departments(\%myconfig);
-  if (@{ $form->{all_departments} || [] }) {
-    $form->{selectdepartment} = "<option>\n";
-
-    map {
-      $form->{selectdepartment} .=
-        "<option>$_->{description}--$_->{id}\n"
-    } (@{ $form->{all_departments} || [] });
-  }
+  $::form->{ALL_DEPARTMENTS} = SL::DB::Manager::Department->get_all;
 
   my $i        = 1;
   my $tax      = 0;
@@ -226,15 +208,14 @@ sub search {
   $::lxdebug->enter_sub;
   $::auth->assert('general_ledger | gl_transactions');
 
-  $::form->all_departments(\%::myconfig);
   $::form->get_lists(
     projects  => { key => "ALL_PROJECTS", all => 1 },
   );
   $::form->{ALL_EMPLOYEES} = SL::DB::Manager::Employee->get_all_sorted(query => [ deleted => 0 ]);
+  $::form->{ALL_DEPARTMENTS} = SL::DB::Manager::Department->get_all;
 
   $::form->header;
   print $::form->parse_html_template('gl/search', {
-    department_label => sub { ("$_[0]{description}--$_[0]{id}")x2 },
     employee_label => sub { "$_[0]{id}--$_[0]{name}" },
   });
 
@@ -316,7 +297,7 @@ sub generate_report {
   );
 
   # add employee here, so that variable is still known and passed in url when choosing a different sort order in resulting table
-  my @hidden_variables = qw(accno source reference department description notes project_id datefrom dateto employee_id datesort category l_subtotal);
+  my @hidden_variables = qw(accno source reference description notes project_id datefrom dateto employee_id datesort category l_subtotal);
   push @hidden_variables, map { "l_${_}" } @columns;
 
   my $employee = $form->{employee_id} ? SL::DB::Employee->new(id => $form->{employee_id})->load->name : '';
@@ -334,12 +315,11 @@ sub generate_report {
   push @date_options, $locale->text('Bis'),  $locale->date(\%myconfig, $form->{dateto},   1)          if ($form->{dateto});
   push @options,      join(' ', @date_options)                                                        if (scalar @date_options);
 
-  if ($form->{department}) {
-    my ($department) = split /--/, $form->{department};
-    push @options, $locale->text('Department') . " : $department";
+  if ($form->{department_id}) {
+    my $department = SL::DB::Manager::Department->find_by( id => $form->{department_id} );
+    push @options, $locale->text('Department') . " : " . $department->description;
   }
 
-
   my $callback = build_std_url('action=generate_report', grep { $form->{$_} } @hidden_variables);
 
   $form->{l_credit_accno}     = 'Y';
@@ -877,9 +857,12 @@ sub form_header {
   $::form->get_lists("projects"  => { "key"       => "ALL_PROJECTS",
                                     "all"       => 0,
                                     "old_id"    => \@old_project_ids },
+
                    "charts"    => { "key"       => "ALL_CHARTS",
                                     "transdate" => $::form->{transdate} });
 
+  $::form->{ALL_DEPARTMENTS} = SL::DB::Manager::Department->get_all;
+
   GL->get_chart_balances('charts' => $::form->{ALL_CHARTS});
 
   my $title      = $::form->{title};
@@ -890,10 +873,6 @@ sub form_header {
   map { $::form->{$_} =~ s/\"/&quot;/g }
     qw(chart taxchart);
 
-  $::form->{selectdepartment} =~ s/ selected//;
-  $::form->{selectdepartment} =~
-    s/option>\Q$::form->{department}\E/option selected>$::form->{department}/;
-
   if ($init) {
     $::request->{layout}->focus("#reference");
     $::form->{taxincluded} = "1";
@@ -1172,7 +1151,7 @@ sub post {
   my $form     = $main::form;
   my $locale   = $main::locale;
 
-  if ($::myconfig{mandatory_departments} && !$form->{department}) {
+  if ($::myconfig{mandatory_departments} && !$form->{department_id}) {
     $form->{saved_message} = $::locale->text('You have to specify a department.');
     update();
     exit;
index ec74206..748ff1b 100644 (file)
@@ -99,11 +99,10 @@ function updateTaxes(row)
         </tr>
 [%- END %]
 
-[%- IF selectdepartment %]
+[%- IF ALL_DEPARTMENTS %]
         <tr>
           <th align=right nowrap>[% 'Department' | $T8 %]</th>
-          <td colspan=3><select name=department>[% selectdepartment %]</select></td>
-          <input type=hidden name=selectdepartment value="[% selectdepartment | html %]">
+          <td>[% L.select_tag('department_id', ALL_DEPARTMENTS, default = department_id, title_key = 'description', with_empty = 1) %]</td>
         </tr>
 [%- END %]
 
index e9ec797..80a4aca 100644 (file)
           <th align=right>[% 'Source' | $T8 %]</th>
           <td><input name=source size=20></td>
         </tr>
-        [%- IF all_departments %]
+        [%- IF ALL_DEPARTMENTS %]
         <tr>
           <th align=right nowrap>[% 'Department' | $T8 %]</th>
-          <td colspan=3>[% L.select_tag('department', all_departments, value_title_sub = \department_label, with_empty = 1) %]</td>
+          <td colspan=3>[% L.select_tag('department_id', ALL_DEPARTMENTS, title_key = 'description', with_empty = 1) %]</td>
         </tr>
         [%- END %]
         <tr>