Neues Feld Firmensignatur in Mandantenkonfiguration
[kivitendo-erp.git] / bin / mozilla / am.pl
index 7549bc1..e141696 100644 (file)
@@ -42,7 +42,9 @@ use SL::User;
 use SL::USTVA;
 use SL::Iconv;
 use SL::TODO;
-use SL::Printer;
+use SL::DB::Printer;
+use SL::DB::Tax;
+use SL::DB::Language;
 use CGI;
 
 require "bin/mozilla/common.pl";
@@ -144,7 +146,7 @@ sub account_header {
       rate           => '',
       taxkey_id      => '',
       pos_ustva      => '',
-      startdate      => '',
+      startdate      => $form->{account_exists} ? '' : DateTime->new(year => 1970, month => 1, day => 1)->to_lxoffice,
     };
 
     push @{ $form->{ACCOUNT_TAXKEYS} }, $newtaxkey_ref;
@@ -336,7 +338,7 @@ sub account_header {
 
   # account where AR_tax or AP_tax is set are not orphaned if they are used as
   # tax-o-matic account
-  if ( $form->{id} && !$form->{orphaned} && ($form->{link} =~ m/(AP_tax|AR_tax)/) ) {
+  if ( $form->{id} && $form->{orphaned} && ($form->{link} =~ m/(AP_tax|AR_tax)/) ) {
     if (SL::DB::Manager::Tax->find_by(chart_id => $form->{id})) {
       $form->{orphaned} = 0;
     }
@@ -394,6 +396,17 @@ sub save_account {
 
   if ($form->{charttype} eq 'A'){
     $form->isblank("category",  $locale->text('Account Type missing!'));
+
+    my $found_valid_taxkey = 0;
+    foreach my $i (0 .. 10) { # 10 is maximum count of taxkeys in form
+      if ($form->{"taxkey_startdate_$i"} and !$form->{"taxkey_del_$i"}) {
+        $found_valid_taxkey = 1;
+        last;
+      }
+    }
+    if ($found_valid_taxkey == 0) {
+      $form->error($locale->text('A valid taxkey is missing!'));
+    }
   }
 
   $form->redirect($locale->text('Account saved!'))
@@ -426,10 +439,6 @@ sub save_as_new_account {
   }
 
   $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!'));
@@ -466,7 +475,7 @@ sub list_account {
     $ca->{link_edit_account} = $link_edit_account . '&id=' . E($ca->{id});
   }
 
-  $form->use_stylesheet("list_accounts.css");
+  $::request->{layout}->use_stylesheet("list_accounts.css");
   $form->{title}       = $locale->text('Chart of Accounts');
 
   $form->header;
@@ -742,7 +751,7 @@ sub language_header {
 
   print $::form->parse_html_template('am/language_header', {
     numberformats => [ '1,000.00', '1000.00', '1.000,00', '1000,00' ],
-    dateformats => [ qw(mm-dd-yy mm/dd/yy dd-mm-yy dd/mm/yy dd.mm.yy yyyy-mm-dd) ],
+    dateformats => [ qw(mm/dd/yy dd/mm/yy dd.mm.yy yyyy-mm-dd) ],
   });
 
   $::lxdebug->leave_sub;
@@ -928,60 +937,6 @@ sub swap_buchungsgruppen {
   $main::lxdebug->leave_sub();
 }
 
-sub edit_defaults {
-  $main::lxdebug->enter_sub();
-
-  my $form     = $main::form;
-  my %myconfig = %main::myconfig;
-  my $locale   = $main::locale;
-
-  # get defaults for account numbers and last numbers
-  AM->defaultaccounts(\%myconfig, \%$form);
-  $form->{ALL_UNITS} = AM->convertible_units(AM->retrieve_all_units(), 'g');
-
-  map { $form->{"defaults_${_}"} = $form->{defaults}->{$_} } keys %{ $form->{defaults} };
-
-  # default language
-  my $all_languages = SL::DB::Manager::Language->get_all;
-
-# EÜR = cash, Bilanzierung = accrual
-
-  foreach my $key (keys %{ $form->{IC} }) {
-    foreach my $accno (sort keys %{ $form->{IC}->{$key} }) {
-      my $array = "ACCNOS_" . uc($key);
-      $form->{$array} ||= [];
-
-      my $value = "${accno}--" . $form->{IC}->{$key}->{$accno}->{description};
-      push @{ $form->{$array} }, {
-        'name'     => $value,
-        'value'    => $value,
-        'selected' => $form->{IC}->{$key}->{$accno}->{id} == $form->{defaults}->{$key},
-      };
-    }
-  }
-
-  $form->{title} = $locale->text('Ranges of numbers and default accounts');
-
-  $form->header();
-  print $form->parse_html_template('am/edit_defaults',
-                                   { ALL_LANGUAGES => $all_languages, });
-
-  $main::lxdebug->leave_sub();
-}
-
-sub save_defaults {
-  $main::lxdebug->enter_sub();
-
-  my $form     = $main::form;
-  my $locale   = $main::locale;
-
-  AM->save_defaults();
-
-  $form->redirect($locale->text('Defaults saved.'));
-
-  $main::lxdebug->leave_sub();
-}
-
 sub _build_cfg_options {
   my $form     = $main::form;
   my %myconfig = %main::myconfig;
@@ -1006,7 +961,8 @@ sub config {
   my %myconfig = %main::myconfig;
   my $locale   = $main::locale;
 
-  _build_cfg_options('dateformat', qw(mm-dd-yy mm/dd/yy dd-mm-yy dd/mm/yy dd.mm.yy yyyy-mm-dd));
+  _build_cfg_options('dateformat', qw(mm/dd/yy dd/mm/yy dd.mm.yy yyyy-mm-dd));
+  _build_cfg_options('timeformat', qw(hh:mm hh:mm:ss));
   _build_cfg_options('numberformat', ('1,000.00', '1000.00', '1.000,00', '1000,00'));
 
   my @formats = ();
@@ -1052,7 +1008,7 @@ sub config {
     { 'name' => $locale->text('Queue'),   'value' => 'queue',   'selected' => $selected{queue}, },
     ];
 
-  $form->{PRINTERS} = [ SL::Printer->all_printers(%::myconfig) ];
+  $form->{PRINTERS} = SL::DB::Manager::Printer->get_all_sorted;
 
   my %countrycodes = User->country_codes;
 
@@ -1066,7 +1022,7 @@ sub config {
   }
 
   $form->{STYLESHEETS} = [];
-  foreach my $item (qw(lx-office-erp.css Win2000.css Mobile.css kivitendo.css)) {
+  foreach my $item (qw(lx-office-erp.css Mobile.css kivitendo.css)) {
     push @{ $form->{STYLESHEETS} }, {
       'name'     => $item,
       'value'    => $item,
@@ -1081,6 +1037,9 @@ sub config {
   $form->{title}               = $locale->text('Edit Preferences for #1', $form->{login});
 
   $form->header();
+
+  $form->{full_signature} = $form->create_email_signature();
+
   print $form->parse_html_template('am/config');
 
   $main::lxdebug->leave_sub();
@@ -1097,7 +1056,7 @@ sub save_preferences {
 
   TODO->save_user_config('login' => $form->{login}, %{ $form->{todo_cfg} || { } });
 
-  if (AM->save_preferences(\%myconfig, $form)) {
+  if (AM->save_preferences($form)) {
     if ($::auth->can_change_password()
         && defined $form->{new_password}
         && ($form->{new_password} ne '********')) {
@@ -1109,10 +1068,6 @@ sub save_preferences {
       }
 
       $::auth->change_password($form->{login}, $form->{new_password});
-
-      $form->{password} = $form->{new_password};
-      $::auth->set_session_value('password', $form->{password});
-      $::auth->create_or_refresh_session();
     }
 
     $form->redirect($locale->text('Preferences saved!'));
@@ -1454,10 +1409,18 @@ sub add_tax {
 
   _get_taxaccount_selection();
 
+  $form->{asset}      = 1;
+  $form->{liability}  = 1;
+  $form->{equity}     = 1;
+  $form->{revenue}    = 1;
+  $form->{expense}    = 1;
+  $form->{costs}      = 1;
+
   $form->header();
 
   my $parameters_ref = {
 #    ChartTypeIsAccount         => $ChartTypeIsAccount,
+    LANGUAGES => SL::DB::Manager::Language->get_all_sorted,
   };
 
   # Ausgabe des Templates
@@ -1478,13 +1441,23 @@ sub edit_tax {
   $form->{title} =  $locale->text('Edit');
 
   AM->get_tax(\%myconfig, \%$form);
+
   _get_taxaccount_selection();
 
+  $form->{asset}      = $form->{chart_categories} =~ 'A' ? 1 : 0;
+  $form->{liability}  = $form->{chart_categories} =~ 'L' ? 1 : 0;
+  $form->{equity}     = $form->{chart_categories} =~ 'Q' ? 1 : 0;
+  $form->{revenue}    = $form->{chart_categories} =~ 'I' ? 1 : 0;
+  $form->{expense}    = $form->{chart_categories} =~ 'E' ? 1 : 0;
+  $form->{costs}      = $form->{chart_categories} =~ 'C' ? 1 : 0;
+
   $form->{rate} = $form->format_amount(\%myconfig, $form->{rate}, 2);
 
   $form->header();
 
   my $parameters_ref = {
+    LANGUAGES => SL::DB::Manager::Language->get_all_sorted,
+    TAX       => SL::DB::Manager::Tax->find_by(id => $form->{id}),
   };
 
   # Ausgabe des Templates
@@ -1545,12 +1518,16 @@ sub save_tax {
 
   $main::auth->assert('config');
 
-  $form->isblank("rate", $locale->text('Taxrate missing!'));
-  $form->isblank("taxdescription", $locale->text('Taxdescription  missing!'));
-  $form->isblank("taxkey", $locale->text('Taxkey  missing!'));
+  $form->error($locale->text('Taxkey  missing!')) unless length($form->{taxkey}) != 0;
+  $form->error($locale->text('Taxdescription  missing!')) unless length($form->{taxdescription}) != 0;
+  $form->error($locale->text('Taxrate missing!')) unless length($form->{rate}) != 0;
 
   $form->{rate} = $form->parse_amount(\%myconfig, $form->{rate});
 
+  if ($form->{taxkey} == 0 and $form->{rate} > 0) {
+    $form->error($locale->text('Taxkey 0 is reserved for rate 0'));
+  }
+
   if ( $form->{rate} < 0 || $form->{rate} >= 100 ) {
     $form->error($locale->text('Tax Percent is a number between 0 and 100'));
   }
@@ -1559,6 +1536,9 @@ sub save_tax {
     $form->error($locale->text('Tax Percent is a number between 0 and 100'));
   }
 
+  my @translation_keys  =  grep { $_ =~ '^translation_\d+' } keys %$form;
+  $form->{translations} = { map { $_ =~ '^translation_(\d+)'; $1 => $form->{$_} } @translation_keys };
+
   AM->save_tax(\%myconfig, \%$form);
   $form->redirect($locale->text('Tax saved!'));
 
@@ -1590,7 +1570,6 @@ sub add_price_factor {
 
   $form->{title}      = $locale->text('Add Price Factor');
   $form->{callback} ||= build_std_url('action=add_price_factor');
-  $form->{fokus}      = 'description';
 
   $form->header();
   print $form->parse_html_template('am/edit_price_factor');
@@ -1609,7 +1588,6 @@ sub edit_price_factor {
 
   $form->{title}      = $locale->text('Edit Price Factor');
   $form->{callback} ||= build_std_url('action=add_price_factor');
-  $form->{fokus}      = 'description';
 
   AM->get_price_factor(\%myconfig, $form);
 
@@ -1697,7 +1675,6 @@ sub add_warehouse {
 
   $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');
@@ -1720,7 +1697,6 @@ sub edit_warehouse {
 
   $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');