$locale->text('CANCELD') für Stornierungen hinzugefügt
[kivitendo-erp.git] / SL / AM.pm
index 8696cba..323556b 100644 (file)
--- a/SL/AM.pm
+++ b/SL/AM.pm
@@ -48,7 +48,7 @@ sub get_account {
   # connect to database
   my $dbh = $form->dbconnect($myconfig);
   my $query =
-    qq!SELECT c.accno, c.description, c.charttype, c.gifi_accno, c.category,! .
+    qq!SELECT c.accno, c.description, c.charttype, c.category,! .
     qq!  c.link, c.pos_bilanz, c.pos_eur, c.new_chart_id, c.valid_from, ! .
     qq!  c.pos_bwa, ! .
     qq!  tk.taxkey_id, tk.pos_ustva, tk.tax_id, ! .
@@ -183,13 +183,13 @@ sub save_account {
   if ($form->{id}) {
     $query = qq|UPDATE chart SET
                 accno = ?, description = ?, charttype = ?,
-                gifi_accno = ?, category = ?, link = ?,
+                category = ?, link = ?,
                 taxkey_id = ?,
                 pos_ustva = ?, pos_bwa   = ?, pos_bilanz = ?,
                 pos_eur = ?, new_chart_id = ?, valid_from = ?
                 WHERE id = ?|;
     @values = ($form->{accno}, $form->{description}, $form->{charttype},
-               $form->{gifi_accno}, $form->{category}, $form->{link},
+               $form->{category}, $form->{link},
                conv_i($taxkey),
                conv_i($form->{pos_ustva}), conv_i($form->{pos_bwa}),
                conv_i($form->{pos_bilanz}), conv_i($form->{pos_eur}),
@@ -205,14 +205,12 @@ sub save_account {
   } else {
     $query = qq|INSERT INTO chart
                 (accno, description, charttype,
-                 gifi_accno, category, link,
-                 taxkey_id,
+                 category, link, taxkey_id,
                  pos_ustva, pos_bwa, pos_bilanz, pos_eur,
                  new_chart_id, valid_from)
                 VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)|;
     @values = ($form->{accno}, $form->{description}, $form->{charttype},
-               $form->{gifi_accno}, $form->{category}, $form->{link},
-               conv_i($taxkey),
+               $form->{category}, $form->{link}, conv_i($taxkey),
                conv_i($form->{pos_ustva}), conv_i($form->{pos_bwa}),
                conv_i($form->{pos_bilanz}), conv_i($form->{pos_eur}),
                conv_i($form->{new_chart_id}),
@@ -1222,36 +1220,85 @@ sub delete_payment {
   $main::lxdebug->leave_sub();
 }
 
-sub load_template {
+
+sub prepare_template_filename {
   $main::lxdebug->enter_sub();
 
-  my ($self, $form) = @_;
+  my ($self, $myconfig, $form) = @_;
+
+  my ($filename, $display_filename);
+
+  if ($form->{type} eq "stylesheet") {
+    $filename = "css/$myconfig->{stylesheet}";
+    $display_filename = $myconfig->{stylesheet};
+
+  } else {
+    $filename = $form->{formname};
+
+    if ($form->{language}) {
+      my ($id, $template_code) = split(/--/, $form->{language});
+      $filename .= "_${template_code}";
+    }
 
-  open(TEMPLATE, "$form->{file}") or $form->error("$form->{file} : $!");
+    if ($form->{printer}) {
+      my ($id, $template_code) = split(/--/, $form->{printer});
+      $filename .= "_${template_code}";
+    }
 
-  while (<TEMPLATE>) {
-    $form->{body} .= $_;
+    $filename .= "." . ($form->{format} eq "html" ? "html" : "tex");
+    $filename =~ s|.*/||;
+    $display_filename = $filename;
+    $filename = "$myconfig->{templates}/$filename";
   }
 
-  close(TEMPLATE);
+  $main::lxdebug->leave_sub();
+
+  return ($filename, $display_filename);
+}
+
+
+sub load_template {
+  $main::lxdebug->enter_sub();
+
+  my ($self, $filename) = @_;
+
+  my ($content, $lines) = ("", 0);
+
+  local *TEMPLATE;
+
+  if (open(TEMPLATE, $filename)) {
+    while (<TEMPLATE>) {
+      $content .= $_;
+      $lines++;
+    }
+    close(TEMPLATE);
+  }
 
   $main::lxdebug->leave_sub();
+
+  return ($content, $lines);
 }
 
 sub save_template {
   $main::lxdebug->enter_sub();
 
-  my ($self, $form) = @_;
+  my ($self, $filename, $content) = @_;
 
-  open(TEMPLATE, ">$form->{file}") or $form->error("$form->{file} : $!");
+  local *TEMPLATE;
 
-  # strip
-  $form->{body} =~ s/\r\n/\n/g;
-  print TEMPLATE $form->{body};
+  my $error = "";
 
-  close(TEMPLATE);
+  if (open(TEMPLATE, ">$filename")) {
+    $content =~ s/\r\n/\n/g;
+    print(TEMPLATE $content);
+    close(TEMPLATE);
+  } else {
+    $error = $!;
+  }
 
   $main::lxdebug->leave_sub();
+
+  return $error;
 }
 
 sub save_preferences {
@@ -1671,7 +1718,7 @@ sub unit_select_data {
     push(@{$select}, { "name" => "", "base_unit" => "", "factor" => "", "selected" => "" });
   }
 
-  foreach my $unit (sort({ $a->{"sortkey"} <=> $b->{"sortkey"} } keys(%{$units}))) {
+  foreach my $unit (sort({ $units->{$a}->{"sortkey"} <=> $units->{$b}->{"sortkey"} } keys(%{$units}))) {
     push(@{$select}, { "name" => $unit,
                        "base_unit" => $units->{$unit}->{"base_unit"},
                        "factor" => $units->{$unit}->{"factor"},
@@ -1690,7 +1737,7 @@ sub unit_select_html {
 
   my $select = "<select name=${name}>";
 
-  foreach my $unit (sort({ $a->{"sortkey"} <=> $b->{"sortkey"} } keys(%{$units}))) {
+  foreach my $unit (sort({ $units->{$a}->{"sortkey"} <=> $units->{$b}->{"sortkey"} } keys(%{$units}))) {
     if (!$convertible_into ||
         ($units->{$convertible_into} &&
          ($units->{$convertible_into}->{"base_unit"} eq $units->{$unit}->{"base_unit"}))) {