Sortieren nach Vorgangsbezeichnung ermöglichen. Fix für Bug 749.
[kivitendo-erp.git] / bin / mozilla / am.pl
index 51f8f69..da221ae 100644 (file)
@@ -38,6 +38,7 @@ use SL::Form;
 use SL::User;
 use SL::USTVA;
 use SL::Iconv;
+use SL::TODO;
 use CGI::Ajax;
 use CGI;
 
@@ -54,6 +55,7 @@ sub delete   { call_sub("delete_$form->{type}"); }
 sub save     { call_sub("save_$form->{type}"); }
 sub edit     { call_sub("edit_$form->{type}"); }
 sub continue { call_sub($form->{"nextsub"}); }
+sub save_as_new { call_sub("save_as_new_$form->{type}"); }
 
 sub add_account {
   $lxdebug->enter_sub();
@@ -372,6 +374,12 @@ sub form_footer {
       . $locale->text('Delete') . qq|">|;
   }
 
+  if ($form->{id} && $form->{type} eq "account") {
+    print qq|
+    <input class=submit type=submit name=action value="|
+      . $locale->text('Save as new') . qq|">|;
+  }
+
   print qq|
 </form>
 
@@ -401,6 +409,36 @@ sub save_account {
   $lxdebug->leave_sub();
 }
 
+sub save_as_new_account {
+  $lxdebug->enter_sub();
+
+  $auth->assert('config');
+
+  $form->isblank("accno",       $locale->text('Account Number missing!'));
+  $form->isblank("description", $locale->text('Account Description missing!'));
+  
+  if ($form->{charttype} eq 'A'){
+    $form->isblank("category",  $locale->text('Account Type missing!'));
+  }
+
+  for my $taxkey (0 .. 9) {
+    if ($form->{"taxkey_id_$taxkey"}) {
+      $form->{"taxkey_id_$taxkey"} = "NEW";
+    }
+  }
+
+  $form->{id} = 0;
+  if ($form->{"original_accno"} &&
+      ($form->{"accno"} eq $form->{"original_accno"})) {
+    $form->error($locale->text('Account Number already used!'));
+  }
+  $form->redirect($locale->text('Account saved!'))
+    if (AM->save_account(\%myconfig, \%$form));
+  $form->error($locale->text('Cannot save account!'));
+
+  $lxdebug->leave_sub();
+}
+
 sub list_account {
   $lxdebug->enter_sub();
 
@@ -1904,7 +1942,7 @@ sub list_printer {
 |;
 
 
-    $column_data{printer_description} = qq|<td><a href="am.pl?action=edit_printer&id=$ref->{id}&callback=$callback">$ref->{printer_description}"</td>|;
+    $column_data{printer_description} = qq|<td><a href="am.pl?action=edit_printer&id=$ref->{id}&callback=$callback">$ref->{printer_description}</td>|;
     $column_data{printer_command}           = qq|<td align=right>$ref->{printer_command}</td>|;
     $column_data{template_code} =
       qq|<td align=right>$ref->{template_code}</td>|;
@@ -2488,9 +2526,9 @@ sub config {
     };
   }
 
-  $myconfig{show_form_details}              = 1 unless (defined($myconfig{show_form_details}));
-  $form->{"menustyle_$myconfig{menustyle}"} = 1;
-  $form->{CAN_CHANGE_PASSWORD}              = $auth->can_change_password();
+  $myconfig{show_form_details} = 1 unless (defined($myconfig{show_form_details}));
+  $form->{CAN_CHANGE_PASSWORD} = $auth->can_change_password();
+  $form->{todo_cfg}            = { TODO->get_user_config('login' => $form->{login}) };
 
   $form->{title}                            = $locale->text('Edit Preferences for #1', $form->{login});
 
@@ -2505,6 +2543,8 @@ sub save_preferences {
 
   $form->{stylesheet} = $form->{usestylesheet};
 
+  TODO->save_user_config('login' => $form->{login}, %{ $form->{todo_cfg} || { } });
+
   $form->redirect($locale->text('Preferences saved!')) if (AM->save_preferences(\%myconfig, \%$form, $webdav));
   $form->error($locale->text('Cannot save preferences!'));
 
@@ -2520,12 +2560,6 @@ sub audit_control {
 
   AM->closedto(\%myconfig, \%$form);
 
-  if ($form->{revtrans}) {
-    $checked{Y} = "checked";
-  } else {
-    $checked{N} = "checked";
-  }
-
   $form->header;
 
   print qq|
@@ -2539,15 +2573,6 @@ sub audit_control {
   <tr>
     <td>
       <table>
-       <tr>
-         <td>|
-    . $locale->text('Enforce transaction reversal for all dates') . qq|</th>
-         <td><input name=revtrans class=radio type=radio value="1" $checked{Y}> |
-    . $locale->text('Yes')
-    . qq| <input name=revtrans class=radio type=radio value="0" $checked{N}> |
-    . $locale->text('No')
-    . qq|</td>
-       </tr>
        <tr>
          <th>| . $locale->text('Close Books up to') . qq|</th>
          <td><input name=closedto size=11 title="$myconfig{dateformat}" value=$form->{closedto}></td>
@@ -2581,17 +2606,12 @@ sub doclose {
 
   AM->closebooks(\%myconfig, \%$form);
 
-  if ($form->{revtrans}) {
+  if ($form->{closedto}) {
     $form->redirect(
-                 $locale->text('Transaction reversal enforced for all dates'));
+                    $locale->text('Books closed up to') . " "
+                      . $locale->date(\%myconfig, $form->{closedto}, 1));
   } else {
-    if ($form->{closedto}) {
-      $form->redirect(
-                     $locale->text('Transaction reversal enforced up to') . " "
-                       . $locale->date(\%myconfig, $form->{closedto}, 1));
-    } else {
-      $form->redirect($locale->text('Books are open'));
-    }
+    $form->redirect($locale->text('Books are open'));
   }
 
   $lxdebug->leave_sub();
@@ -2602,7 +2622,7 @@ sub edit_units {
 
   $auth->assert('config');
 
-  $units = AM->retrieve_units(\%myconfig, $form, $form->{"unit_type"}, "resolved_");
+  $units = AM->retrieve_units(\%myconfig, $form, "resolved_");
   AM->units_in_use(\%myconfig, $form, $units);
   map({ $units->{$_}->{"BASE_UNIT_DDBOX"} = AM->unit_select_data($units, $units->{$_}->{"base_unit"}, 1); } keys(%{$units}));
 
@@ -2626,12 +2646,12 @@ sub edit_units {
     $i++;
   }
 
-  $units = AM->retrieve_units(\%myconfig, $form, $form->{"unit_type"});
+  $units = AM->retrieve_units(\%myconfig, $form);
   $ddbox = AM->unit_select_data($units, undef, 1);
 
-  my $updownlink = build_std_url("action=swap_units", "unit_type");
+  my $updownlink = build_std_url("action=swap_units");
 
-  $form->{"title"} = sprintf($locale->text("Add and edit %s"), $form->{"unit_type"} eq "dimension" ? $locale->text("dimension units") : $locale->text("service units"));
+  $form->{"title"} = $locale->text("Add and edit units");
   $form->header();
   print($form->parse_html_template("am/edit_units",
                                    { "UNITS"               => \@unit_list,
@@ -2648,7 +2668,7 @@ sub add_unit {
   $auth->assert('config');
 
   $form->isblank("new_name", $locale->text("The name is missing."));
-  $units = AM->retrieve_units(\%myconfig, $form, $form->{"unit_type"});
+  $units = AM->retrieve_units(\%myconfig, $form);
   $all_units = AM->retrieve_units(\%myconfig, $form);
   $form->show_generic_error($locale->text("A unit with this name does already exist.")) if ($all_units->{$form->{"new_name"}});
 
@@ -2671,7 +2691,7 @@ sub add_unit {
          });
   }
 
-  AM->add_unit(\%myconfig, $form, $form->{"new_name"}, $base_unit, $factor, $form->{"unit_type"}, \@languages);
+  AM->add_unit(\%myconfig, $form, $form->{"new_name"}, $base_unit, $factor, \@languages);
 
   $form->{"saved_message"} = $locale->text("The unit has been saved.");
 
@@ -2705,7 +2725,7 @@ sub save_unit {
 
   $auth->assert('config');
 
-  $old_units = AM->retrieve_units(\%myconfig, $form, $form->{"unit_type"}, "resolved_");
+  $old_units = AM->retrieve_units(\%myconfig, $form, "resolved_");
   AM->units_in_use(\%myconfig, $form, $old_units);
 
   @languages = AM->language(\%myconfig, $form, 1);
@@ -2771,7 +2791,7 @@ sub save_unit {
     }
   }
 
-  AM->save_units(\%myconfig, $form, $form->{"unit_type"}, $new_units, \@delete_units);
+  AM->save_units(\%myconfig, $form, $new_units, \@delete_units);
 
   $form->{"saved_message"} = $locale->text("The units have been saved.");
 
@@ -2901,9 +2921,7 @@ sub swap_units {
   $auth->assert('config');
 
   my $dir = $form->{"dir"} eq "down" ? "down" : "up";
-  my $unit_type = $form->{"unit_type"} eq "dimension" ?
-    "dimension" : "service";
-  AM->swap_units(\%myconfig, $form, $dir, $form->{"name"}, $unit_type);
+  AM->swap_units(\%myconfig, $form, $dir, $form->{"name"});
 
   edit_units();
 
@@ -3132,3 +3150,131 @@ sub swap_price_factors {
   $lxdebug->leave_sub();
 }
 
+sub add_warehouse {
+  $lxdebug->enter_sub();
+
+  $auth->assert('config');
+
+  $form->{title}      = $locale->text('Add Warehouse');
+  $form->{callback} ||= build_std_url('action=add_warehouse');
+  $form->{fokus}      = 'description';
+
+  $form->header();
+  print $form->parse_html_template('am/edit_warehouse');
+
+  $lxdebug->leave_sub();
+}
+
+sub edit_warehouse {
+  $lxdebug->enter_sub();
+
+  $auth->assert('config');
+
+  AM->get_warehouse(\%myconfig, $form);
+
+  $form->get_lists('employees' => 'EMPLOYEES');
+
+  $form->{title}      = $locale->text('Edit Warehouse');
+  $form->{callback} ||= build_std_url('action=list_warehouses');
+  $form->{fokus}      = 'description';
+
+  $form->header();
+  print $form->parse_html_template('am/edit_warehouse');
+
+  $lxdebug->leave_sub();
+}
+
+sub list_warehouses {
+  $lxdebug->enter_sub();
+
+  $auth->assert('config');
+
+  AM->get_all_warehouses(\%myconfig, $form);
+
+  my $previous;
+  foreach my $current (@{ $form->{WAREHOUSES} }) {
+    if ($previous) {
+      $previous->{next_id}    = $current->{id};
+      $current->{previous_id} = $previous->{id};
+    }
+
+    $previous = $current;
+  }
+
+  $form->{callback} = build_std_url('action=list_warehouses');
+  $form->{title}    = $locale->text('Warehouses');
+  $form->{url_base} = build_std_url('callback');
+
+  $form->header();
+  print $form->parse_html_template('am/list_warehouses');
+
+  $lxdebug->leave_sub();
+}
+
+sub save_warehouse {
+  $lxdebug->enter_sub();
+
+  $auth->assert('config');
+
+  $form->isblank("description", $locale->text('Description missing!'));
+
+  $form->{number_of_new_bins} = $form->parse_amount(\%myconfig, $form->{number_of_new_bins});
+
+  AM->save_warehouse(\%myconfig, $form);
+
+  $form->{callback} .= '&saved_message=' . E($locale->text('Warehouse saved.')) if ($form->{callback});
+
+  $form->redirect($locale->text('Warehouse saved.'));
+
+  $lxdebug->leave_sub();
+}
+
+sub swap_warehouses {
+  $lxdebug->enter_sub();
+
+  $auth->assert('config');
+
+  AM->swap_sortkeys(\%myconfig, $form, 'warehouse');
+  list_warehouses();
+
+  $lxdebug->leave_sub();
+}
+
+sub delete_warehouse {
+  $lxdebug->enter_sub();
+
+  $auth->assert('config');
+
+  if (!$form->{confirmed}) {
+    $form->{title} = $locale->text('Confirmation');
+
+    $form->header();
+    print $form->parse_html_template('am/confirm_delete_warehouse');
+    exit 0;
+  }
+
+  if (AM->delete_warehouse(\%myconfig, $form)) {
+    $form->{callback} .= '&saved_message=' . E($locale->text('Warehouse deleted.')) if ($form->{callback});
+    $form->redirect($locale->text('Warehouse deleted.'));
+
+  } else {
+    $form->error($locale->text('The warehouse could not be deleted because it has already been used.'));
+  }
+
+  $lxdebug->leave_sub();
+}
+
+sub save_bin {
+  $lxdebug->enter_sub();
+
+  $auth->assert('config');
+
+  AM->save_bins(\%myconfig, $form);
+
+  $form->{callback} .= '&saved_message=' . E($locale->text('Bins saved.')) if ($form->{callback});
+
+  $form->redirect($locale->text('Bins saved.'));
+
+  $lxdebug->leave_sub();
+}
+