Lieferbedingungen analog zu Zahlungsbedingungen eingeführt.
[kivitendo-erp.git] / bin / mozilla / io.pl
index ca3d050..c1bc770 100644 (file)
@@ -47,6 +47,7 @@ use SL::CT;
 use SL::IC;
 use SL::IO;
 
+use SL::DB::Default;
 use SL::DB::Language;
 use SL::DB::Printer;
 use SL::Helper::Flash;
@@ -102,7 +103,7 @@ use Data::Dumper;
 sub _check_io_auth {
   $main::auth->assert('part_service_assembly_edit   | vendor_invoice_edit       | sales_order_edit    | invoice_edit |' .
                 'request_quotation_edit       | sales_quotation_edit      | purchase_order_edit | ' .
-                'purchase_delivery_order_edit | sales_delivery_order_edit');
+                'purchase_delivery_order_edit | sales_delivery_order_edit | part_service_assembly_details');
 }
 
 ########################################
@@ -123,6 +124,10 @@ sub display_row {
 
   my ($stock_in_out, $stock_in_out_title);
 
+  my $defaults = AM->get_defaults();
+  $form->{show_weight} = $defaults->{show_weight};
+  $form->{weightunit} = $defaults->{weightunit};
+
   my $is_purchase        = (first { $_ eq $form->{type} } qw(request_quotation purchase_order purchase_delivery_order)) || ($form->{script} eq 'ir.pl');
   my $show_min_order_qty =  first { $_ eq $form->{type} } qw(request_quotation purchase_order);
   my $is_delivery_order  = $form->{type} =~ /_delivery_order$/;
@@ -150,7 +155,7 @@ sub display_row {
     {  id => 'qty',           width => 5,     value => $locale->text('Qty'),                  display => 1, },
     {  id => 'price_factor',  width => 5,     value => $locale->text('Price Factor'),         display => !$is_delivery_order, },
     {  id => 'unit',          width => 5,     value => $locale->text('Unit'),                 display => 1, },
-    {  id => 'weight',        width => 5,     value => $locale->text('Weight'),               display => 1, },
+    {  id => 'weight',        width => 5,     value => $locale->text('Weight'),               display => $defaults->{show_weight}, },
     {  id => 'serialnr',      width => 10,    value => $locale->text('Serial No.'),           display => 0, },
     {  id => 'projectnr',     width => 10,    value => $locale->text('Project'),              display => 0, },
     {  id => 'sellprice',     width => 15,    value => $locale->text('Price'),                display => !$is_delivery_order, },
@@ -208,7 +213,7 @@ sub display_row {
   _update_custom_variables();
 
   my $totalweight = 0;
-  my $defaults = AM->get_defaults();
+
   # rows
 
   my @ROWS;
@@ -232,7 +237,6 @@ sub display_row {
     if ((!$form->{"prices_$i"}) || ($form->{"new_pricegroup_$i"} == $form->{"old_pricegroup_$i"})) {
         $form->{"sellprice_$i"} *= AM->convert_unit($form->{"selected_unit_$i"}, $form->{"unit_old_$i"}, $all_units) || 1;
         $form->{"lastcost_$i"} *= AM->convert_unit($form->{"selected_unit_$i"}, $form->{"unit_old_$i"}, $all_units) || 1;
-        $form->{"weight_$i"} *= AM->convert_unit($form->{"selected_unit_$i"}, $form->{"unit_old_$i"}, $all_units) || 1;
         $form->{"unit_old_$i"}   = $form->{"selected_unit_$i"};
     }
     my $this_unit = $form->{"unit_$i"};
@@ -251,6 +255,7 @@ sub display_row {
     } else {
       $column_data{price_factor} = ' ';
     }
+    $form->{"weight_$i"} *= AM->convert_unit($form->{"selected_unit_$i"}, $form->{"partunit_$i"}, $all_units) || 1;
 
     $column_data{"unit"} = AM->unit_select_html($all_units, "unit_$i", $this_unit, $form->{"id_$i"} ? $form->{"unit_$i"} : undef);
 # / unit ending
@@ -330,7 +335,7 @@ sub display_row {
     $column_data{linetotal}   = $form->format_amount(\%myconfig, $linetotal, 2);
     $column_data{bin}         = $form->{"bin_$i"};
 
-    $column_data{weight}      = $form->format_amount(\%myconfig, $form->{"qty_$i"} * $form->{"weight_$i"}, 3) . ' ' . $defaults->{weightunit};
+    $column_data{weight}      = $form->format_amount(\%myconfig, $form->{"qty_$i"} * $form->{"weight_$i"}, 3) . ' ' . $defaults->{weightunit} if $defaults->{show_weight};
 
     if ($is_delivery_order) {
       $column_data{stock_in_out} =  calculate_stock_in_out($i);
@@ -664,11 +669,7 @@ sub check_form {
   my $count = 0;
 
   # remove any makes or model rows
-  if ($form->{item} eq 'part') {
-    map { $form->{$_} = $form->parse_amount(\%myconfig, $form->{$_}) }
-      qw(listprice sellprice lastcost weight rop);
-
-  } elsif ($form->{item} eq 'assembly') {
+  if ($form->{item} eq 'assembly') {
 
     # fuer assemblies auskommentiert. seiteneffekte? ;-) wird die woanders benoetigt?
     #$form->{sellprice} = 0;
@@ -701,10 +702,7 @@ sub check_form {
     $form->redo_rows(\@flds, \@a, $count, $form->{assembly_rows});
     $form->{assembly_rows} = $count;
 
-  } elsif ($form->{item} eq 'service') {
-    map { $form->{$_} = $form->parse_amount(\%myconfig, $form->{$_}) } qw(listprice sellprice lastcost);
-
-  } else {
+  } elsif ($form->{item} !~ m{^(?:part|service)$}) {
     remove_emptied_rows(1);
 
     $form->{creditremaining} -= &invoicetotal;
@@ -946,7 +944,7 @@ sub quotation {
     map({ $form->{"${_}_${i}"} = $form->parse_amount(\%myconfig,
                                                      $form->{"${_}_${i}"})
             if ($form->{"${_}_${i}"}) }
-        qw(ship qty sellprice listprice basefactor discount));
+        qw(ship qty sellprice listprice basefactor discount lastcost));
   }
 
   &prepare_order;
@@ -991,7 +989,6 @@ sub edit_e_mail {
   my $attachment_filename = $form->generate_attachment_filename();
   my $subject             = $form->{subject} || $form->generate_email_subject();
 
-  $::request->{layout}->focus($form->{"email"} ? "#subject" : "#email");
   $form->header;
 
   my (@dont_hide_key_list, %dont_hide_key, @hidden_keys);
@@ -1220,6 +1217,10 @@ sub print_form {
 
   _check_io_auth();
 
+  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;
+
   my ($old_form) = @_;
 
   my $inv       = "inv";
@@ -1364,6 +1365,7 @@ sub print_form {
 
   my $language_saved = $form->{language_id};
   my $payment_id_saved = $form->{payment_id};
+  my $delivery_term_id_saved = $form->{delivery_term_id};
   my $salesman_id_saved = $form->{salesman_id};
   my $cp_id_saved = $form->{cp_id};
   my $taxzone_id_saved = $form->{taxzone_id};
@@ -1373,6 +1375,7 @@ sub print_form {
 
   $form->{language_id} = $language_saved;
   $form->{payment_id} = $payment_id_saved;
+  $form->{delivery_term_id} = $delivery_term_id_saved;
   $form->{taxzone_id} = $taxzone_id_saved;
   $form->{currency} = $currency_saved;
 
@@ -1434,8 +1437,8 @@ sub print_form {
   if ($shipto) {
     if (   $form->{formname} eq 'purchase_order'
         || $form->{formname} eq 'request_quotation') {
-      $form->{shiptoname}   = $myconfig{company};
-      $form->{shiptostreet} = $myconfig{address};
+      $form->{shiptoname}   = $defaults->company;
+      $form->{shiptostreet} = $defaults->address;
     } else {
       map { $form->{"shipto$_"} = $form->{$_} } @a;
     }
@@ -1443,8 +1446,6 @@ sub print_form {
 
   $form->{notes} =~ s/^\s+//g;
 
-  $form->{templates} = "$myconfig{templates}";
-
   delete $form->{printer_command};
 
   $form->{language} = $form->get_template_language(\%myconfig);
@@ -1524,7 +1525,7 @@ sub print_form {
   push @template_files, "$form->{formname}.$extension";
   push @template_files, "default.$extension";
   @template_files = uniq @template_files;
-  $form->{IN}     = first { -f "$myconfig{templates}/$_" } @template_files;
+  $form->{IN}     = first { -f ($defaults->templates . "/$_") } @template_files;
 
   if (!defined $form->{IN}) {
     $::form->error($::locale->text('Cannot find matching template for this print request. Please contact your template maintainer. I tried these: #1.', join ', ', map { "'$_'"} @template_files));