Bugfix zu Bug 789: Ansprechpartner zeigen jetzt auch den Vornamen an
[kivitendo-erp.git] / bin / mozilla / oe.pl
index de1722e..f6b5686 100644 (file)
 
 use POSIX qw(strftime);
 
+use SL::FU;
 use SL::OE;
 use SL::IR;
 use SL::IS;
 use SL::PE;
 use SL::ReportGenerator;
-use List::Util qw(max reduce);
+use List::Util qw(max reduce sum);
 
 require "bin/mozilla/io.pl";
 require "bin/mozilla/arap.pl";
@@ -318,7 +319,6 @@ sub prepare_order {
     $form->{"discount_$i"}  = $form->format_amount(\%myconfig, $form->{"discount_$i"} * ($form->{id} ? 100 : 1));
     $form->{"sellprice_$i"} = $form->format_amount(\%myconfig, $form->{"sellprice_$i"});
     $form->{"qty_$i"}       = $form->format_amount(\%myconfig, $form->{"qty_$i"});
-    map { $form->{"${_}_$i"} =~ s/\"/"/g } qw(partnumber description unit);
   }
 
   $lxdebug->leave_sub();
@@ -431,6 +431,19 @@ sub form_header {
 
   $credittext = $locale->text('Credit Limit exceeded!!!');
 
+  my $follow_up_vc                =  $form->{ $form->{vc} eq 'customer' ? 'customer' : 'vendor' };
+  $follow_up_vc                   =~ s/--.*?//;
+  $TMPL_VAR{follow_up_trans_info} =  ($form->{type} =~ /_quotation$/ ? $form->{quonumber} : $form->{ordnumber}) . " ($follow_up_vc)";
+
+  if ($form->{id}) {
+    my $follow_ups = FU->follow_ups('trans_id' => $form->{id});
+
+    if (scalar @{ $follow_ups }) {
+      $TMPL_VAR{num_follow_ups}     = scalar                    @{ $follow_ups };
+      $TMPL_VAR{num_due_follow_ups} = sum map { $_->{due} * 1 } @{ $follow_ups };
+    }
+  }
+
   $onload = ($form->{resubmit} && ($form->{format} eq "html")) ? "window.open('about:blank','Beleg'); document.oe.target = 'Beleg';document.oe.submit()"
           : ($form->{resubmit})                                ? "document.oe.submit()"
           : ($creditwarning)                                   ? "alert('$credittext')"
@@ -439,7 +452,7 @@ sub form_header {
   $onload .= qq|;setupDateFormat('|. $myconfig{dateformat} .qq|', '|. $locale->text("Falsches Datumsformat!") .qq|')|;
   $onload .= qq|;setupPoints('|.   $myconfig{numberformat} .qq|', '|. $locale->text("wrongformat") .qq|')|;
   $TMPL_VAR{onload} = $onload;
-  
+
   $form->{javascript} .= qq|<script type="text/javascript" src="js/show_form_details.js"></script>|;
   $form->{javascript} .= qq|<script type="text/javascript" src="js/show_history.js"></script>|;
   $form->{javascript} .= qq|<script type="text/javascript" src="js/show_vc_details.js"></script>|;
@@ -545,7 +558,7 @@ sub update {
 
   set_headings($form->{"id"} ? "edit" : "add");
 
-  map { $form->{$_} = $form->parse_amount(\%myconfig, $form->{$_}) } qw(exchangerate creditlimit creditremaining) unless $recursive_call;
+  map { $form->{$_} = $form->parse_amount(\%myconfig, $form->{$_}) } qw(exchangerate) unless $recursive_call;
   $form->{update} = 1;
       
   $payment_id = $form->{payment_id} if $form->{payment_id};
@@ -1032,49 +1045,24 @@ sub orders {
 
   $report->set_columns(%column_defs);
   $report->set_column_order(@columns);
-
   $report->set_export_options('orders', @hidden_variables);
-
   $report->set_sort_indicator($form->{sort}, 1);
 
   my @options;
-  if ($form->{customer}) {
-    push @options, $locale->text('Customer') . " : $form->{customer}";
-  }
-  if ($form->{vendor}) {
-    push @options, $locale->text('Vendor') . " : $form->{vendor}";
-  }
-  if ($form->{department}) {
-    ($department) = split /--/, $form->{department};
-    push @options, $locale->text('Department') . " : $department";
-  }
-  if ($form->{ordnumber}) {
-    push @options, $locale->text('Order Number') . " : $form->{ordnumber}";
-  }
-  if ($form->{notes}) {
-    push @options, $locale->text('Notes') . " : $form->{notes}";
-  }
-  if ($form->{transaction_description}) {
-    push @options, $locale->text('Transaction description') . " : $form->{transaction_description}";
-  }
-  if ($form->{transdatefrom}) {
-    push @options, $locale->text('From') . "&nbsp;" . $locale->date(\%myconfig, $form->{transdatefrom}, 1);
-  }
-  if ($form->{transdateto}) {
-    push @options, $locale->text('Bis') . "&nbsp;" . $locale->date(\%myconfig, $form->{transdateto}, 1);
-  }
-  if ($form->{open}) {
-    push @options, $locale->text('Open');
-  }
-  if ($form->{closed}) {
-    push @options, $locale->text('Closed');
-  }
-  if ($form->{delivered}) {
-    push @options, $locale->text('Delivered');
-  }
-  if ($form->{notdelivered}) {
-    push @options, $locale->text('Not delivered');
-  }
+
+  push @options, $locale->text('Customer') . " : $form->{customer}"                                       if $form->{customer};
+  push @options, $locale->text('Vendor') . " : $form->{vendor}"                                           if $form->{vendor};
+  ($department) = split /--/, $form->{department};
+  push @options, $locale->text('Department') . " : $department"                                           if $form->{department};
+  push @options, $locale->text('Order Number') . " : $form->{ordnumber}"                                  if $form->{ordnumber};
+  push @options, $locale->text('Notes') . " : $form->{notes}"                                             if $form->{notes};
+  push @options, $locale->text('Transaction description') . " : $form->{transaction_description}"         if $form->{transaction_description};
+  push @options, $locale->text('From') . "&nbsp;" . $locale->date(\%myconfig, $form->{transdatefrom}, 1)  if $form->{transdatefrom};
+  push @options, $locale->text('Bis') . "&nbsp;" . $locale->date(\%myconfig, $form->{transdateto}, 1)     if $form->{transdateto};
+  push @options, $locale->text('Open')                                                                    if $form->{open};
+  push @options, $locale->text('Closed')                                                                  if $form->{closed};
+  push @options, $locale->text('Delivered')                                                               if $form->{delivered};
+  push @options, $locale->text('Not delivered')                                                           if $form->{notdelivered};
 
   $report->set_options('top_info_text'        => join("\n", @options),
                        'raw_top_info_text'    => $form->parse_html_template('oe/orders_top'),
@@ -1579,9 +1567,6 @@ sub invoice {
 
   map { $form->{"select$_"} = "" } ($form->{vc}, currency);
 
-  map { $form->{$_} = $form->parse_amount(\%myconfig, $form->{$_}) }
-    qw(creditlimit creditremaining);
-
   $currency = $form->{currency};
   &invoice_links;
 
@@ -1951,14 +1936,58 @@ sub poso {
       qw(partnumber description unit);
   }
 
-  map { $form->{$_} = $form->format_amount(\%myconfig, $form->{$_}, 0, "0") }
-    qw(creditlimit creditremaining);
-
   &update;
 
   $lxdebug->leave_sub();
 }
 
+sub delivery_order {
+  $lxdebug->enter_sub();
+
+  if ($form->{type} =~ /^sales/) {
+    $auth->assert('sales_delivery_order_edit');
+
+    $form->{vc}    = 'customer';
+    $form->{type}  = 'sales_delivery_order';
+
+  } else {
+    $auth->assert('purchase_delivery_order_edit');
+
+    $form->{vc}    = 'vendor';
+    $form->{type}  = 'purchase_delivery_order';
+  }
+
+  require "bin/mozilla/do.pl";
+
+  $form->{cp_id}           *= 1;
+  $form->{transdate}        = $form->current_date(\%myconfig);
+  delete $form->{duedate};
+
+  $form->{closed}           = 0;
+
+  $form->{old_employee_id}  = $form->{employee_id};
+  $form->{old_salesman_id}  = $form->{salesman_id};
+
+  # reset
+  map { delete $form->{$_} } qw(id subject message cc bcc printed emailed queued creditlimit creditremaining discount tradediscount oldinvtotal);
+
+  for $i (1 .. $form->{rowcount}) {
+    map { $form->{"${_}_${i}"} = $form->parse_amount(\%myconfig, $form->{"${_}_${i}"}) if ($form->{"${_}_${i}"}) } qw(ship qty sellprice listprice basefactor);
+  }
+
+  my %old_values = map { $_ => $form->{$_} } qw(customer_id oldcustomer customer vendor_id oldvendor vendor);
+
+  order_links();
+
+  prepare_order();
+
+  map { $form->{$_} = $old_values{$_} if ($old_values{$_}) } keys %old_values;
+
+  update();
+
+  $lxdebug->leave_sub();
+}
+
 sub e_mail {
   $lxdebug->enter_sub();
 
@@ -1995,6 +2024,8 @@ sub display_form {
 
   check_oe_access();
 
+  retrieve_partunits() if ($form->{type} =~ /_delivery_order$/);
+
   $form->{"taxaccounts"} =~ s/\s*$//;
   $form->{"taxaccounts"} =~ s/^\s*//;
   foreach my $accno (split(/\s*/, $form->{"taxaccounts"})) {
@@ -2023,3 +2054,21 @@ sub display_form {
   $lxdebug->leave_sub();
 }
 
+sub report_for_todo_list {
+  $lxdebug->enter_sub();
+
+  my $quotations = OE->transactions_for_todo_list();
+  my $content;
+
+  if (@{ $quotations }) {
+    my $edit_url = build_std_url('script=oe.pl', 'action=edit', 'type=sales_quotation', 'vc=customer');
+
+    $content     = $form->parse_html_template('oe/report_for_todo_list', { 'QUOTATIONS' => $quotations,
+                                                                           'edit_url'   => $edit_url });
+  }
+
+  $lxdebug->leave_sub();
+
+  return $content;
+}
+