Administrationsbereich mit Menüsystem versehen
[kivitendo-erp.git] / SL / CT.pm
index 02a5522..44707f9 100644 (file)
--- a/SL/CT.pm
+++ b/SL/CT.pm
@@ -42,6 +42,7 @@ use Data::Dumper;
 use SL::Common;
 use SL::CVar;
 use SL::DBUtils;
+use SL::DB::Default;
 use SL::FU;
 use SL::Notes;
 use SL::TransNumber;
@@ -68,11 +69,12 @@ sub get_tuple {
   my $ref = $sth->fetchrow_hashref("NAME_lc");
 
   map { $form->{$_} = $ref->{$_} } keys %$ref;
+  $sth->finish;
 
-  # remove any trailing whitespace
-  $form->{curr} =~ s/\s*$//;
+  #get name of currency instead of id:
+  $query = qq|SELECT name AS curr FROM currencies WHERE id=?|;
+  ($form->{curr}) = selectrow_query($form, $dbh, $query, conv_i($form->{currency_id}));
 
-  $sth->finish;
   if ( $form->{salesman_id} ) {
     my $query =
       qq|SELECT ct.name AS salesman | .
@@ -275,7 +277,7 @@ sub save_customer {
     $query = qq|SELECT nextval('id')|;
     ($form->{id}) = selectrow_query($form, $dbh, $query);
 
-    $query = qq|INSERT INTO customer (id, name) VALUES (?, '')|;
+    $query = qq|INSERT INTO customer (id, name, currency_id) VALUES (?, '', (SELECT currency_id FROM defaults))|;
     do_query($form, $dbh, $query, $form->{id});
   }
 
@@ -319,7 +321,7 @@ sub save_customer {
     qq|user_password = ?, | .
     qq|c_vendor_id = ?, | .
     qq|klass = ?, | .
-    qq|curr = ?, | .
+    qq|currency_id = (SELECT id FROM currencies WHERE name = ?), | .
     qq|taxincluded_checked = ? | .
     qq|WHERE id = ?|;
   my @values = (
@@ -362,7 +364,7 @@ sub save_customer {
     $form->{user_password},
     $form->{c_vendor_id},
     conv_i($form->{klass}),
-    substr($form->{currency}, 0, 3),
+    $form->{currency},
     $form->{taxincluded_checked} ne '' ? $form->{taxincluded_checked} : undef,
     $form->{id}
     );
@@ -422,7 +424,7 @@ sub save_vendor {
     $query = qq|SELECT nextval('id')|;
     ($form->{id}) = selectrow_query($form, $dbh, $query);
 
-    $query = qq|INSERT INTO vendor (id, name) VALUES (?, '')|;
+    $query = qq|INSERT INTO vendor (id, name, currency_id) VALUES (?, '', (SELECT currency_id FROM defaults))|;
     do_query($form, $dbh, $query, $form->{id});
 
     my $vendornumber      = SL::TransNumber->new(type   => 'vendor',
@@ -471,7 +473,7 @@ sub save_vendor {
     qq|  username = ?, | .
     qq|  user_password = ?, | .
     qq|  v_customer_id = ?, | .
-    qq|  curr = ? | .
+    qq|  currency_id = (SELECT id FROM currencies WHERE name = ?) | .
     qq|WHERE id = ?|;
   my @values = (
     $form->{vendornumber},
@@ -511,7 +513,7 @@ sub save_vendor {
     $form->{username},
     $form->{user_password},
     $form->{v_customer_id},
-    substr($form->{currency}, 0, 3),
+    $form->{currency},
     $form->{id}
     );
   do_query($form, $dbh, $query, @values);
@@ -1079,6 +1081,10 @@ sub parse_excel_file {
   my ($self, $myconfig, $form) = @_;
   my $locale = $main::locale;
 
+  my $defaults = SL::DB::Default->get;
+  $form->error($::locale->text('No print templates have been created for this client yet. Please do so in the client configuration.')) if !$defaults->templates;
+  $form->{templates} = $defaults->templates;
+
   $form->{formname}   = 'sales_quotation';
   $form->{type}   = 'sales_quotation';
   $form->{format} = 'excel';
@@ -1121,8 +1127,6 @@ sub parse_excel_file {
 
   $form->{notes} =~ s/^\s+//g;
 
-  $form->{templates} = $myconfig->{templates};
-
   delete $form->{printer_command};
 
   $form->get_employee_info($myconfig);