calculate_qty (Formel): auf Dialog umgestellt
[kivitendo-erp.git] / bin / mozilla / oe.pl
index 4a8e316..7832b2e 100644 (file)
@@ -297,14 +297,14 @@ sub setup_oe_action_bar {
   my $form   = $::form;
 
   my $has_active_periodic_invoice;
-  if ($params{obj}) {
+  if ($params{oe_obj}) {
     $has_active_periodic_invoice =
-         $params{obj}->is_type('sales_order')
-      && $params{obj}->periodic_invoices_config
-      && $params{obj}->periodic_invoices_config->active
-      && (   !$params{obj}->periodic_invoices_config->end_date
-          || ($params{obj}->periodic_invoices_config->end_date > DateTime->today_local))
-      && $params{obj}->periodic_invoices_config->get_previous_billed_period_start_date;
+         $params{oe_obj}->is_type('sales_order')
+      && $params{oe_obj}->periodic_invoices_config
+      && $params{oe_obj}->periodic_invoices_config->active
+      && (   !$params{oe_obj}->periodic_invoices_config->end_date
+          || ($params{oe_obj}->periodic_invoices_config->end_date > DateTime->today_local))
+      && $params{oe_obj}->periodic_invoices_config->get_previous_billed_period_start_date;
   }
 
   my $allow_invoice      = $params{is_req_quo}
@@ -622,7 +622,11 @@ sub form_header {
     is_pur_ord   => scalar($form->{type} =~ /purchase_order$/),
   );
 
-  setup_oe_action_bar(%type_check_vars);
+  setup_oe_action_bar(
+    %type_check_vars,
+    oe_obj => $TMPL_VAR->{oe_obj},
+    vc_obj => $TMPL_VAR->{vc_obj},
+  );
 
   $form->header;
   if ($form->{CFDD_shipto} && $form->{CFDD_shipto_id} ) {
@@ -1031,7 +1035,7 @@ sub orders {
   $form->{l_open}              = $form->{l_closed} = "Y" if ($form->{open}      && $form->{closed});
   $form->{l_delivered}         = "Y"                     if ($form->{delivered} && $form->{notdelivered});
   $form->{l_periodic_invoices} = "Y"                     if ($form->{periodic_invoices_active} && $form->{periodic_invoices_inactive});
-  $form->{l_edit_exp}          = "Y"                     if $::instance_conf->get_feature_experimental && (any { $form->{type} eq $_ } qw(sales_order purchase_order));
+  $form->{l_edit_exp}          = "Y"                     if $::instance_conf->get_feature_experimental && (any { $form->{type} eq $_ } qw(sales_order purchase_order sales_quotation request_quotation));
   map { $form->{"l_${_}"} = 'Y' } qw(order_probability expected_billing_date expected_netamount) if $form->{l_order_probability_expected_billing_date};
 
   my $attachment_basename;
@@ -1261,7 +1265,7 @@ sub orders {
 
     $row->{$ordnumber}->{link} = $edit_url . "&id=" . E($oe->{id}) . "&callback=${callback}";
 
-    $row->{edit_exp}->{data}   = $oe->{ordnumber};
+    $row->{edit_exp}->{data}   = $oe->{$ordnumber};
     $row->{edit_exp}->{link}   = build_std_url('script=controller.pl', 'action=Order/edit', "type=$form->{type}", 'id=' . E($oe->{id}));
 
     my $row_set = [ $row ];
@@ -2042,12 +2046,41 @@ sub oe_delivery_order_from_order {
   my $order = SL::DB::Order->new(id => $::form->{id})->load;
   $order->flatten_to_form($::form, format_amounts => 1);
 
+  # hack: add partsgroup for first row if it does not exists,
+  # because _remove_billed_or_delivered_rows and _remove_full_delivered_rows
+  # determine fields to handled by existing fields for the first row. If partsgroup
+  # is missing there, for deleted rows the partsgroup_field is not emptied and in
+  # update_delivery_order it will not considered an empty row ...
+  $::form->{partsgroup_1} = '' if !exists $::form->{partsgroup_1};
+
   # fake last empty row
   $::form->{rowcount}++;
 
+  _update_ship();
   delivery_order();
 }
 
+sub oe_invoice_from_order {
+
+  return if !$::form->{id};
+
+  my $order = SL::DB::Order->new(id => $::form->{id})->load;
+  $order->flatten_to_form($::form, format_amounts => 1);
+
+  # hack: add partsgroup for first row if it does not exists,
+  # because _remove_billed_or_delivered_rows and _remove_full_delivered_rows
+  # determine fields to handled by existing fields for the first row. If partsgroup
+  # is missing there, for deleted rows the partsgroup_field is not emptied and in
+  # update_delivery_order it will not considered an empty row ...
+  $::form->{partsgroup_1} = '' if !exists $::form->{partsgroup_1};
+
+  # fake last empty row
+  $::form->{rowcount}++;
+
+  _update_ship();
+  invoice();
+}
+
 sub yes {
   call_sub($main::form->{yes_nextsub});
 }
@@ -2154,7 +2187,7 @@ sub edit_periodic_invoices_config {
   }
 
   $::form->header(no_layout => 1);
-  print $::form->parse_html_template('oe/edit_periodic_invoices_config', $config);
+  print $::form->parse_html_template('oe/edit_periodic_invoices_config', {config => $config});
 
   $::lxdebug->leave_sub();
 }