Auftrags-Controller: Workflow -> Rechnung (Speichern und Rechnung erfassen)
authorBernd Bleßmann <bernd@kivitendo-premium.de>
Fri, 8 Dec 2017 15:04:07 +0000 (16:04 +0100)
committerBernd Bleßmann <bernd@kivitendo-premium.de>
Mon, 29 Jan 2018 09:03:58 +0000 (10:03 +0100)
SL/Controller/Order.pm
bin/mozilla/oe.pl
js/kivi.Order.js

index 8355dda..04319e0 100644 (file)
@@ -39,10 +39,10 @@ use Rose::Object::MakeMethods::Generic
 __PACKAGE__->run_before('_check_auth');
 
 __PACKAGE__->run_before('_recalc',
-                        only => [ qw(save save_and_delivery_order print create_pdf send_email) ]);
+                        only => [ qw(save save_and_delivery_order save_and_invoice print create_pdf send_email) ]);
 
 __PACKAGE__->run_before('_get_unalterable_data',
-                        only => [ qw(save save_and_delivery_order print create_pdf send_email) ]);
+                        only => [ qw(save save_and_delivery_order save_and_invoice print create_pdf send_email) ]);
 
 #
 # actions
@@ -340,6 +340,28 @@ sub action_save_and_delivery_order {
   $self->redirect_to(@redirect_params);
 }
 
+# save the order and redirect to the frontend subroutine for a new
+# invoice
+sub action_save_and_invoice {
+  my ($self) = @_;
+
+  my $errors = $self->_save();
+
+  if (scalar @{ $errors }) {
+    $self->js->flash('error', $_) foreach @{ $errors };
+    return $self->js->render();
+  }
+  flash_later('info', $::locale->text('The order has been saved'));
+
+  my @redirect_params = (
+    controller => 'oe.pl',
+    action     => 'oe_invoice_from_order',
+    id         => $self->order->id,
+  );
+
+  $self->redirect_to(@redirect_params);
+}
+
 # set form elements in respect to a changed customer or vendor
 #
 # This action is called on an change of the customer/vendor picker.
@@ -1123,6 +1145,10 @@ sub _setup_edit_action_bar {
           t8('Save and Delivery Order'),
           call      => [ 'kivi.Order.save_and_delivery_order', $::instance_conf->get_order_warn_duplicate_parts ],
         ],
+        action => [
+          t8('Save and Invoice'),
+          call      => [ 'kivi.Order.save_and_invoice', $::instance_conf->get_order_warn_duplicate_parts ],
+        ],
 
       ], # end of combobox "Save"
 
@@ -1349,7 +1375,7 @@ java script functions
 
 =item * credit limit
 
-=item * more workflows (save as new / invoice)
+=item * more workflows (save as new, quotation, purchase order)
 
 =item * price sources: little symbols showing better price / better discount
 
@@ -1450,6 +1476,13 @@ editor or on text processing application).
 
 A warning when leaving the page without saveing unchanged inputs.
 
+=item *
+
+Workflows for delivery order and invoice are in the menu "Save", because the
+order is saved before opening the new document form. Nevertheless perhaps these
+workflow buttons should be put under "Workflows".
+
+
 =back
 
 =head1 AUTHOR
index 4a8e316..8c2af08 100644 (file)
@@ -2048,6 +2048,19 @@ sub oe_delivery_order_from_order {
   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);
+
+  # fake last empty row
+  $::form->{rowcount}++;
+
+  invoice();
+}
+
 sub yes {
   call_sub($main::form->{yes_nextsub});
 }
index 5d891d5..cce54f4 100644 (file)
@@ -55,6 +55,16 @@ namespace('kivi.Order', function(ns) {
     $.post("controller.pl", data, kivi.eval_json_result);
   };
 
+  ns.save_and_invoice = function(warn_on_duplicates) {
+    if (!ns.check_cv()) return;
+    if (warn_on_duplicates && !ns.check_save_duplicate_parts()) return;
+
+    var data = $('#order_form').serializeArray();
+    data.push({ name: 'action', value: 'Order/save_and_invoice' });
+
+    $.post("controller.pl", data, kivi.eval_json_result);
+  };
+
   ns.delete_order = function() {
     var data = $('#order_form').serializeArray();
     data.push({ name: 'action', value: 'Order/delete' });