Überbleibsel von der Unterstützung für html2ps entfernt.
[kivitendo-erp.git] / bin / mozilla / do.pl
index b262500..79d8172 100644 (file)
@@ -156,7 +156,8 @@ sub order_links {
 
   my $editing = $form->{id};
 
-  DO->retrieve();
+  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});
@@ -415,9 +416,9 @@ sub orders {
   $form->{rowcount} = scalar @{ $form->{DO} };
 
   my @columns = qw(
-    transdate
+    ids                     transdate
     id                      donumber
-    ordnumber               oreqnumber
+    ordnumber
     name                    employee
     shipvia                 globalprojectnumber
     transaction_description
@@ -445,7 +446,6 @@ sub orders {
     'id'                      => { 'text' => $locale->text('ID'), },
     'donumber'                => { 'text' => $locale->text('Delivery Order'), },
     'ordnumber'               => { 'text' => $locale->text('Order'), },
-    'oreqnumber'              => { 'text' => $locale->text('Order Request Number'), },
     'name'                    => { 'text' => $form->{vc} eq 'customer' ? $locale->text('Customer') : $locale->text('Vendor'), },
     'employee'                => { 'text' => $locale->text('Salesperson'), },
     'shipvia'                 => { 'text' => $locale->text('Ship via'), },
@@ -455,13 +455,14 @@ sub orders {
     'delivered'               => { 'text' => $locale->text('Delivered'), },
   );
 
-  foreach my $name (qw(id transdate donumber ordnumber oreqnumber name employee shipvia)) {
+  foreach my $name (qw(id transdate donumber ordnumber name employee shipvia)) {
     $column_defs{$name}->{link} = $href . "&sort=$name";
   }
 
   $form->{"l_type"} = "Y";
   map { $column_defs{$_}->{visible} = $form->{"l_${_}"} ? 1 : 0 } @columns;
-  $column_defs{ids}->{visible} = $allow_multiple_orders ? 'HTML' : 0;
+
+  $column_defs{ids}->{visible} = 'HTML';
 
   $report->set_columns(%column_defs);
   $report->set_column_order(@columns);
@@ -509,10 +510,12 @@ sub orders {
     push @options, $locale->text('Not delivered');
   }
 
-  $report->set_options('top_info_text'       => join("\n", @options),
-                       'output_format'       => 'HTML',
-                       'title'               => $form->{title},
-                       'attachment_basename' => $attachment_basename . strftime('_%Y%m%d', localtime time),
+  $report->set_options('top_info_text'        => join("\n", @options),
+                       'raw_top_info_text'    => $form->parse_html_template('do/orders_top'),
+                       'raw_bottom_info_text' => $form->parse_html_template('do/orders_bottom'),
+                       'output_format'        => 'HTML',
+                       'title'                => $form->{title},
+                       'attachment_basename'  => $attachment_basename . strftime('_%Y%m%d', localtime time),
     );
   $report->set_options_from_form();
 
@@ -524,7 +527,8 @@ sub orders {
 
   my $edit_url       = build_std_url('action=edit', 'type', 'vc');
   my $edit_order_url = build_std_url('script=oe.pl', 'type=' . ($form->{type} eq 'sales_delivery_order' ? 'sales_order' : 'purchase_order'), 'action=edit');
-  my $edit_oreq_url  = build_std_url('script=pkoreq.pl', 'action=edit');
+
+  my $idx            = 1;
 
   foreach $dord (@{ $form->{DO} }) {
     $dord->{open}      = $dord->{closed}    ? $locale->text('No')  : $locale->text('Yes');
@@ -532,11 +536,19 @@ sub orders {
 
     my $row = { map { $_ => { 'data' => $dord->{$_} } } @columns };
 
-    $row->{donumber}->{link}   = $edit_url       . "&id=" . E($dord->{id})      . "&callback=${callback}";
-    $row->{ordnumber}->{link}  = $edit_order_url . "&id=" . E($dord->{oe_id})   . "&callback=${callback}";
-    $row->{oreqnumber}->{link} = $edit_oreq_url  . "&id=" . E($dord->{oreq_id}) . "&callback=${callback}";
+    $row->{ids}  = {
+      'raw_data' =>   $cgi->hidden('-name' => "trans_id_${idx}", '-value' => $dord->{id})
+                    . $cgi->checkbox('-name' => "multi_id_${idx}", '-value' => 1, '-label' => ''),
+      'valign'   => 'center',
+      'align'    => 'center',
+    };
+
+    $row->{donumber}->{link}  = $edit_url       . "&id=" . E($dord->{id})      . "&callback=${callback}";
+    $row->{ordnumber}->{link} = $edit_order_url . "&id=" . E($dord->{oe_id})   . "&callback=${callback}";
 
     $report->add_data($row);
+
+    $idx++;
   }
 
   $report->generate_with_headers();
@@ -674,8 +686,8 @@ sub invoice {
 
   $form->{currency}     = $currency;
   $form->{exchangerate} = "";
-  $form->{forex}        = ($exchangerate = $form->check_exchangerate(\%myconfig, $form->{currency}, $form->{invdate}, $buysell));
-  $form->{exchangerate} = $exchangerate if ($form->{forex});
+  $form->{forex}        = $form->check_exchangerate(\%myconfig, $form->{currency}, $form->{invdate}, $buysell);
+  $form->{exchangerate} = $form->{forex} if ($form->{forex});
 
   prepare_invoice();
 
@@ -707,6 +719,69 @@ sub invoice {
   $lxdebug->leave_sub();
 }
 
+sub invoice_multi {
+  $lxdebug->enter_sub();
+
+  check_do_access();
+  $auth->assert($form->{type} eq 'sales_delivery_order' ? 'invoice_edit' : 'vendor_invoice_edit');
+
+  my @do_ids = map { $form->{"trans_id_$_"} } grep { $form->{"multi_id_$_"} } (1..$form->{rowcount});
+
+  if (!scalar @do_ids) {
+    $form->show_generic_error($locale->text('You have not selected any delivery order.'), 'back_button' => 1);
+  }
+
+  map { delete $form->{$_} } grep { m/^(?:trans|multi)_id_\d+/ } keys %{ $form };
+
+  if (!DO->retrieve('vc' => $form->{vc}, 'ids' => \@do_ids)) {
+    $form->show_generic_error($form->{vc} eq 'customer' ?
+                              $locale->text('You cannot create an invoice for delivery orders for different customers.') :
+                              $locale->text('You cannot create an invoice for delivery orders from different vendors.'),
+                              'back_button' => 1);
+  }
+
+  $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') {
+    $form->{title}  = $locale->text('Add Vendor Invoice');
+    $form->{script} = 'ir.pl';
+    $script         = "ir";
+    $buysell        = 'sell';
+
+  } else {
+    $form->{title}  = $locale->text('Add Sales Invoice');
+    $form->{script} = 'is.pl';
+    $script         = "is";
+    $buysell        = 'buy';
+  }
+
+  map { delete $form->{$_} } qw(id subject message cc bcc printed emailed queued);
+
+  $form->{rowcount} = 0;
+  foreach my $ref (@{ $form->{form_details} }) {
+    $form->{rowcount}++;
+    map { $form->{"${_}_$form->{rowcount}"} = $ref->{$_} } keys %{ $ref };
+    map { $form->{"${_}_$form->{rowcount}"} = $form->format_amount(\%myconfig, $ref->{$_}) } qw(qty sellprice discount lastcost);
+  }
+  delete $form->{form_details};
+
+  $locale = new Locale "$myconfig{countrycode}", "$script";
+
+  require "bin/mozilla/$form->{script}";
+
+  invoice_links();
+  prepare_invoice();
+  display_form();
+
+  $lxdebug->leave_sub();
+}
+
 sub save_as_new {
   $lxdebug->enter_sub();
 
@@ -759,6 +834,8 @@ sub calculate_stock_in_out {
     return '';
   }
 
+  AM->retrieve_all_units();
+
   my $in_out   = $form->{type} =~ /^sales/ ? 'out' : 'in';
   my $sinfo    = DO->unpack_stock_information('packed' => $form->{"stock_${in_out}_${i}"});
 
@@ -766,7 +843,7 @@ sub calculate_stock_in_out {
 
   my $content  = $form->format_amount_units('amount'      => $sum * 1,
                                             'part_unit'   => $form->{"partunit_$i"},
-                                            'amount_unit' => $units->{$form->{"partunit_$i"}}->{base_unit},
+                                            'amount_unit' => $all_units->{$form->{"partunit_$i"}}->{base_unit},
                                             'conv_units'  => 'convertible_not_smaller',
                                             'max_places'  => 2);
   $content    .= qq| <input type="button" onclick="open_stock_in_out_window('${in_out}', $i);" value="?">|;
@@ -856,14 +933,11 @@ sub display_stock_in_form {
 
   my $part_info  = IC->get_basic_part_info('id' => $form->{parts_id});
 
-  my $units      = AM->retrieve_units(\%myconfig, $form, "dimension");
+  my $units      = AM->retrieve_units(\%myconfig, $form);
   my $units_data = AM->unit_select_data($units, undef, undef, $part_info->{unit});
 
-  my $access     = $auth->check_right($form->{login}, 'all_warehouses') ? undef : $form->{login};
-
   $form->get_lists('warehouses' => { 'key'    => 'WAREHOUSES',
-                                     'bins'   => 'BINS',
-                                     'access' => $access, });
+                                     'bins'   => 'BINS' });
 
   redo_stock_info('stock_info' => $stock_info, 'add_empty_row' => !$form->{closed});
 
@@ -905,7 +979,7 @@ sub stock_out_form {
 
   my $part_info  = IC->get_basic_part_info('id' => $form->{parts_id});
 
-  my $units      = AM->retrieve_units(\%myconfig, $form, "dimension");
+  my $units      = AM->retrieve_units(\%myconfig, $form);
   my $units_data = AM->unit_select_data($units, undef, undef, $part_info->{unit});
 
   my @contents   = DO->get_item_availability('parts_id' => $form->{parts_id});
@@ -989,7 +1063,7 @@ sub transfer_in_and_close {
   my @all_requests;
 
   if (@part_ids) {
-    my $units         = AM->retrieve_units(\%myconfig, $form, "dimension");
+    my $units         = AM->retrieve_units(\%myconfig, $form);
     my %part_info_map = IC->get_basic_part_info('id' => \@part_ids);
     my %request_map;
 
@@ -1046,7 +1120,7 @@ sub transfer_out_and_close {
   my @all_requests;
 
   if (@part_ids) {
-    my $units         = AM->retrieve_units(\%myconfig, $form, "dimension");
+    my $units         = AM->retrieve_units(\%myconfig, $form);
     my %part_info_map = IC->get_basic_part_info('id' => \@part_ids);
     my %request_map;