generic translations strict
[kivitendo-erp.git] / bin / mozilla / do.pl
index 370411d..7f83bf3 100644 (file)
@@ -121,7 +121,8 @@ sub edit {
   }
 
   if ($form->{print_and_save}) {
-    $form->{action}   = "print";
+    $form->{action}   = "dispatcher";
+    $form->{action_print} = "1";
     $form->{resubmit} = 1;
     $language_id      = $form->{language_id};
     $printer_id       = $form->{printer_id};
@@ -159,14 +160,19 @@ sub order_links {
   DO->retrieve('vc'  => $form->{vc},
                'ids' => $form->{id});
 
-  $payment_id  = $form->{payment_id}  if ($form->{payment_id});
-  $language_id = $form->{language_id} if ($form->{language_id});
-  $taxzone_id  = $form->{taxzone_id}  if ($form->{taxzone_id});
-  $salesman_id = $form->{salesman_id} if ($editing);
+  $form->backup_vars(qw(payment_id language_id taxzone_id salesman_id taxincluded cp_id intnotes));
+  $form->{shipto} = 1 if $form->{id};
 
+  # get customer / vendor
+  if ($form->{vc} eq 'vendor') {
+    IR->get_vendor(\%myconfig, \%$form);
+  } else {
+    IS->get_customer(\%myconfig, \%$form);
+  }
 
-  $taxincluded    = $form->{taxincluded};
-  $form->{shipto} = 1 if $form->{id};
+  $form->restore_vars(qw(payment_id language_id taxzone_id intnotes cp_id));
+  $form->restore_vars(qw(taxincluded)) if $form->{id};
+  $form->restore_vars(qw(salesman_id)) if $editing;
 
   if ($form->{"all_$form->{vc}"}) {
     unless ($form->{"$form->{vc}_id"}) {
@@ -174,25 +180,11 @@ sub order_links {
     }
   }
 
-  $cp_id    = $form->{cp_id};
-  $intnotes = $form->{intnotes};
-
-  $form->{cp_id} = $cp_id;
-
-  $form->{payment_id}  = $payment_id  if ($payment_id);
-  $form->{language_id} = $language_id if ($language_id);
-  $form->{taxzone_id}  = $taxzone_id  if ($taxzone_id);
-  $form->{intnotes}    = $intnotes    if ($intnotes);
-
   ($form->{ $form->{vc} })  = split /--/, $form->{ $form->{vc} };
   $form->{"old$form->{vc}"} = qq|$form->{$form->{vc}}--$form->{"$form->{vc}_id"}|;
 
-  $form->{taxincluded} = $taxincluded if ($form->{id});
-
   $form->{employee} = "$form->{employee}--$form->{employee_id}";
 
-  $form->{salesman_id} = $salesman_id if ($editing);
-
   $lxdebug->leave_sub();
 }
 
@@ -227,8 +219,6 @@ sub prepare_order {
     (my $dec_qty) = ($form->{"qty_$i"} =~ /\.(\d+)/);
     $dec_qty = length $dec_qty;
     $form->{"qty_$i"} = $form->format_amount(\%myconfig, $form->{"qty_$i"}, $dec_qty);
-
-    map { $form->{"${_}_$i"} =~ s/\"/"/g } qw(partnumber description unit);
   }
 
   $lxdebug->leave_sub();
@@ -281,10 +271,15 @@ sub form_header {
     if ($form->{format} eq "html") {
       $form->{onload} = "window.open('about:blank','Beleg'); document.do.target = 'Beleg';";
     }
+    # emulate click for resubmitting actions
+    $form->{onload} .= "document.do.${_}.click(); " for grep { /^action_/ } keys %$form;
     $form->{onload} .= "document.do.submit();"
   }
 
   $form->header();
+  # Fix für Bug 1082 Erwartet wird: 'abteilungsNAME--abteilungsID'
+  $form->{department} .= '--' . $form->{department_id};
+
   print $form->parse_html_template('do/form_header');
 
   $lxdebug->leave_sub();
@@ -346,7 +341,6 @@ sub update_delivery_order {
 
       } else {
 
-        map { $form->{item_list}[$i]{$_} =~ s/\"/"/g }    qw(partnumber description unit);
         map { $form->{"${_}_$i"} = $form->{item_list}[0]{$_} } keys %{ $form->{item_list}[0] };
 
         $form->{"marge_price_factor_$i"} = $form->{item_list}->[0]->{price_factor};
@@ -409,7 +403,7 @@ sub orders {
 
   ($form->{ $form->{vc} }, $form->{"${form->{vc}}_id"}) = split(/--/, $form->{ $form->{vc} });
 
-  $form->{sort} ||= 'transdate';
+  report_generator_set_default_sort('transdate', 1);
 
   DO->transactions();
 
@@ -455,8 +449,9 @@ sub orders {
     'delivered'               => { 'text' => $locale->text('Delivered'), },
   );
 
-  foreach my $name (qw(id transdate donumber ordnumber name employee shipvia)) {
-    $column_defs{$name}->{link} = $href . "&sort=$name";
+  foreach my $name (qw(id transdate donumber ordnumber name employee shipvia transaction_description)) {
+    my $sortdir                 = $form->{sort} eq $name ? 1 - $form->{sortdir} : $form->{sortdir};
+    $column_defs{$name}->{link} = $href . "&sort=$name&sortdir=$sortdir";
   }
 
   $form->{"l_type"} = "Y";
@@ -467,9 +462,9 @@ sub orders {
   $report->set_columns(%column_defs);
   $report->set_column_order(@columns);
 
-  $report->set_export_options('orders', @hidden_variables);
+  $report->set_export_options('orders', @hidden_variables, qw(sort sortdir));
 
-  $report->set_sort_indicator($form->{sort}, 1);
+  $report->set_sort_indicator($form->{sort}, $form->{sortdir});
 
   my @options;
   if ($form->{customer}) {
@@ -492,10 +487,10 @@ sub orders {
     push @options, $locale->text('Transaction description') . " : $form->{transaction_description}";
   }
   if ($form->{transdatefrom}) {
-    push @options, $locale->text('From') . " " . $locale->date(\%myconfig, $form->{transdatefrom}, 1);
+    push @options, $locale->text('From') . " " . $locale->date(\%myconfig, $form->{transdatefrom}, 1);
   }
   if ($form->{transdateto}) {
-    push @options, $locale->text('Bis') . " " . $locale->date(\%myconfig, $form->{transdateto}, 1);
+    push @options, $locale->text('Bis') . " " . $locale->date(\%myconfig, $form->{transdateto}, 1);
   }
   if ($form->{open}) {
     push @options, $locale->text('Open');
@@ -648,22 +643,21 @@ sub invoice {
   check_do_access();
   $auth->assert($form->{type} eq 'purchase_delivery_order' ? 'vendor_invoice_edit' : 'invoice_edit');
 
-  $form->{close_do_ids} = $form->{id};
-
-  $form->{deliverydate} = $form->{transdate};
-  $form->{transdate}    = $form->{invdate} = $form->current_date(\%myconfig);
-  $form->{duedate}      = $form->current_date(\%myconfig, $form->{invdate}, $form->{terms} * 1);
+  $form->{convert_from_do_ids} = $form->{id};
+  $form->{deliverydate}        = $form->{transdate};
+  $form->{transdate}           = $form->{invdate} = $form->current_date(\%myconfig);
+  $form->{duedate}             = $form->current_date(\%myconfig, $form->{invdate}, $form->{terms} * 1);
+  $form->{defaultcurrency}     = $form->get_default_currency(\%myconfig);
 
-  $form->{id}     = '';
-  $form->{closed} = 0;
   $form->{rowcount}--;
 
-  $form->{defaultcurrency} = $form->get_default_currency(\%myconfig);
+  delete @{$form}{qw(id closed delivered)};
 
   if ($form->{type} eq 'purchase_delivery_order') {
     $form->{title}  = $locale->text('Add Vendor Invoice');
     $form->{script} = 'ir.pl';
     $script         = "ir";
+    $buysell        = 'sell';
 
   } else {
     $form->{title}  = $locale->text('Add Sales Invoice');
@@ -742,16 +736,22 @@ sub invoice_multi {
                               'back_button' => 1);
   }
 
-  $form->{close_do_ids}    = join ' ', @do_ids;
-  $form->{deliverydate}    = $form->{transdate};
-  $form->{transdate}       = $form->current_date(\%myconfig);
-  $form->{duedate}         = $form->current_date(\%myconfig, $form->{invdate}, $form->{terms} * 1);
-  $form->{type}            = "invoice";
-  $form->{closed}          = 0;
-  $form->{defaultcurrency} = $form->get_default_currency(\%myconfig);
+  my $source_type              = $form->{type};
+  $form->{convert_from_do_ids} = join ' ', @do_ids;
+  # bei der auswahl von mehreren Lieferscheinen fuer eine Rechnung, die einfach in donumber_array
+  # zwischenspeichern (DO.pm) und als ' '-separierte Liste wieder zurueckschreiben
+  # Hinweis: delete gibt den wert zurueck und loescht danach das element (nett und einfach)
+  # $shell: perldoc perlunc; /delete EXPR
+  $form->{donumber}           = delete $form->{donumber_array};
+  $form->{deliverydate}        = $form->{transdate};
+  $form->{transdate}           = $form->current_date(\%myconfig);
+  $form->{duedate}             = $form->current_date(\%myconfig, $form->{invdate}, $form->{terms} * 1);
+  $form->{type}                = "invoice";
+  $form->{closed}              = 0;
+  $form->{defaultcurrency}     = $form->get_default_currency(\%myconfig);
 
   my $buysell;
-  if ($form->{type} eq 'purchase_delivery_order') {
+  if ($source_type eq 'purchase_delivery_order') {
     $form->{title}  = $locale->text('Add Vendor Invoice');
     $form->{script} = 'ir.pl';
     $script         = "ir";
@@ -769,8 +769,12 @@ sub invoice_multi {
   $form->{rowcount} = 0;
   foreach my $ref (@{ $form->{form_details} }) {
     $form->{rowcount}++;
+    $ref->{reqdate} ||= $ref->{dord_transdate}; # copy transdates into each invoice row
     map { $form->{"${_}_$form->{rowcount}"} = $ref->{$_} } keys %{ $ref };
     map { $form->{"${_}_$form->{rowcount}"} = $form->format_amount(\%myconfig, $ref->{$_}) } qw(qty sellprice discount lastcost);
+               $form->{"discount_$form->{rowcount}"}   = $form->{"discount_$form->{rowcount}"}  * 100; #s.a. Bug 1151
+               # Anm.: Eine Änderung des discounts in der SL/DO.pm->retrieve (select (doi.discount * 100) as discount) ergibt in psql einen
+               # Wert von 10.0000001490116. Ferner ist der Rabatt in der Rechnung dann bei 1.0 (?). Deswegen lasse ich das hier. jb 10.10.09
   }
   delete $form->{form_details};
 
@@ -1216,6 +1220,19 @@ sub transfer_out {
   $lxdebug->leave_sub();
 }
 
+sub mark_closed {
+  $lxdebug->enter_sub();
+
+  DO->close_orders('ids' => [ $form->{id} ]);
+
+  $form->{closed} = 1;
+
+  update();
+
+  $lxdebug->leave_sub();
+}
+
+
 sub yes {
   call_sub($form->{yes_nextsub});
 }
@@ -1227,3 +1244,14 @@ sub no {
 sub update {
   call_sub($form->{update_nextsub} || $form->{nextsub} || 'update_delivery_order');
 }
+
+sub dispatcher {
+  foreach my $action (qw(update ship_to print e_mail save transfer_out transfer_in mark_closed save_as_new invoice delete)) {
+    if ($form->{"action_${action}"}) {
+      call_sub($action);
+      return;
+    }
+  }
+
+  $form->error($locale->text('No action defined.'));
+}