Lieferscheine im Einkauf und Verkauf. Bisher nur gemerget, noch nicht getestet.
[kivitendo-erp.git] / bin / mozilla / oe.pl
index cb875d1..2a90fc6 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";
@@ -431,6 +432,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 +453,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>|;
@@ -1953,6 +1967,53 @@ sub poso {
   $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();
 
@@ -1989,6 +2050,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"})) {
@@ -2017,3 +2080,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;
+}
+