Projekt

Allgemein

Profil

« Zurück | Weiter » 

Revision 9619d8be

Von Bernd Bleßmann vor mehr als 2 Jahren hinzugefügt

  • ID 9619d8be6c536504ae5f5b17e27eff1cba35e2a2
  • Vorgänger 2fd4736b
  • Nachfolger e73be2a8

Auftrags-Controller: Workflows zum Controller selber vereinheitlicht

Es gibt nun eine Methode für die Worklows und das Workflow-Ziel
wird übergeben.

Unterschiede anzeigen:

SL/Controller/Order.pm
824 824
  );
825 825
}
826 826

  
827
# workflow from sales order to sales quotation
828
sub action_save_and_sales_quotation {
827
# workflows to all types of this controller
828
sub action_save_and_order_workflow {
829 829
  $_[0]->save_and_redirect_to(
830
    action     => 'sales_or_request_for_quotation',
831
    type       => $_[0]->type,
832
  );
833
}
834

  
835
# workflow from sales order to sales quotation
836
sub action_save_and_request_for_quotation {
837
  $_[0]->save_and_redirect_to(
838
    action     => 'sales_or_request_for_quotation',
839
    type       => $_[0]->type,
840
  );
841
}
842

  
843
# workflow from sales quotation to sales order
844
sub action_save_and_sales_order {
845
  $_[0]->save_and_redirect_to(
846
    action     => 'sales_or_purchase_order',
847
    type       => $_[0]->type,
848
    use_shipto => $::form->{use_shipto},
849
  );
850
}
851

  
852
# workflow from rfq to purchase order
853
sub action_save_and_purchase_order {
854
  $_[0]->save_and_redirect_to(
855
    action     => 'sales_or_purchase_order',
830
    action     => 'order_workflow',
856 831
    type       => $_[0]->type,
832
    to_type    => $::form->{to_type},
857 833
    use_shipto => $::form->{use_shipto},
858 834
  );
859 835
}
......
868 844
  );
869 845
}
870 846

  
871
sub action_sales_or_purchase_order {
847
sub action_order_workflow {
872 848
  my ($self) = @_;
873 849

  
874 850
  $self->load_order;
875 851

  
876
  my $destination_type = $::form->{type} eq sales_quotation_type()   ? sales_order_type()
877
                       : $::form->{type} eq request_quotation_type() ? purchase_order_type()
878
                       : $::form->{type} eq purchase_order_type()    ? sales_order_type()
879
                       : $::form->{type} eq sales_order_type()       ? purchase_order_type()
880
                       : '';
852
  my $destination_type = $::form->{to_type} ? $::form->{to_type} : '';
881 853

  
882 854
  # check for direct delivery
883 855
  # copy shipto in custom shipto (custom shipto will be copied by new_from() in case)
......
888 860
  }
889 861

  
890 862
  $self->order(SL::DB::Order->new_from($self->order, destination_type => $destination_type));
891
  $self->{converted_from_oe_id} = delete $::form->{id};
863

  
864
  # no linked records from order to quotations
865
  if (any { $destination_type eq $_ } (sales_quotation_type(), request_quotation_type())) {
866
    delete $::form->{id};
867
    delete $::form->{$_} for qw(converted_from_oe_id converted_from_orderitems_ids);
868
  } else {
869
    $self->{converted_from_oe_id} = delete $::form->{id};
870
  }
892 871

  
893 872
  # set item ids to new fake id, to identify them as new items
894 873
  foreach my $item (@{$self->order->items_sorted}) {
......
926 905
  );
927 906
}
928 907

  
929
sub action_sales_or_request_for_quotation {
930
  my ($self) = @_;
931

  
932
  $self->load_order;
933

  
934
  my $destination_type = $::form->{type} eq sales_order_type() ? sales_quotation_type() : request_quotation_type();
935

  
936
  $self->order(SL::DB::Order->new_from($self->order, destination_type => $destination_type));
937
  delete $::form->{id};
938

  
939
  # no linked records from order to quotations
940
  delete $::form->{$_} for qw(converted_from_oe_id converted_from_orderitems_ids);
941

  
942
  # set item ids to new fake id, to identify them as new items
943
  foreach my $item (@{$self->order->items_sorted}) {
944
    $item->{new_fake_id} = join('_', 'new', Time::HiRes::gettimeofday(), int rand 1000000000000);
945
  }
946

  
947
  # change form type
948
  $::form->{type} = $destination_type;
949
  $self->type($self->init_type);
950
  $self->cv  ($self->init_cv);
951
  $self->check_auth;
952

  
953
  $self->recalc();
954
  $self->get_unalterable_data();
955
  $self->pre_render();
956

  
957
  # trigger rendering values for second row as hidden, because they
958
  # are loaded only on demand. So we need to keep the values from the
959
  # source.
960
  $_->{render_second_row} = 1 for @{ $self->order->items_sorted };
961

  
962
  $self->render(
963
    'order/form',
964
    title => $self->get_title_for('edit'),
965
    %{$self->{template_args}}
966
  );
967
}
968

  
969 908
# set form elements in respect to a changed customer or vendor
970 909
#
971 910
# This action is called on an change of the customer/vendor picker.
......
2344 2283
        ],
2345 2284
        action => [
2346 2285
          t8('Save and Quotation'),
2347
          call     => [ 'kivi.submit_ajax_form', $self->url_for(action => "save_and_sales_quotation"), '#order_form' ],
2286
          call     => [ 'kivi.submit_ajax_form', $self->url_for(action => "save_and_order_workflow", to_type => sales_quotation_type()), '#order_form' ],
2348 2287
          checks   => [ @req_trans_cost_art, @req_cusordnumber ],
2349 2288
          only_if  => (any { $self->type eq $_ } (sales_order_type())),
2350 2289
          disabled => !$may_edit_create ? t8('You do not have the permissions to access this function.') : undef,
2351 2290
        ],
2352 2291
        action => [
2353 2292
          t8('Save and RFQ'),
2354
          call     => [ 'kivi.submit_ajax_form', $self->url_for(action => "save_and_request_for_quotation"), '#order_form' ],
2293
          call     => [ 'kivi.submit_ajax_form', $self->url_for(action => "save_and_order_workflow", to_type => request_quotation_type()), '#order_form' ],
2355 2294
          only_if  => (any { $self->type eq $_ } (purchase_order_type())),
2356 2295
          disabled => !$may_edit_create ? t8('You do not have the permissions to access this function.') : undef,
2357 2296
        ],
2358 2297
        action => [
2359 2298
          t8('Save and Sales Order'),
2360
          call     => [ 'kivi.submit_ajax_form', $self->url_for(action => "save_and_sales_order"), '#order_form' ],
2299
          call     => [ 'kivi.submit_ajax_form', $self->url_for(action => "save_and_order_workflow", to_type => sales_order_type()), '#order_form' ],
2361 2300
          checks   => [ @req_trans_cost_art ],
2362 2301
          only_if  => (any { $self->type eq $_ } (sales_quotation_type(), purchase_order_type())),
2363 2302
          disabled => !$may_edit_create ? t8('You do not have the permissions to access this function.') : undef,
2364 2303
        ],
2365 2304
        action => [
2366 2305
          t8('Save and Purchase Order'),
2367
          call      => [ 'kivi.Order.purchase_order_check_for_direct_delivery' ],
2306
          call      => [ 'kivi.Order.purchase_order_check_for_direct_delivery', { to_type => purchase_order_type() } ],
2368 2307
          checks    => [ @req_trans_cost_art, @req_cusordnumber ],
2369 2308
          only_if   => (any { $self->type eq $_ } (sales_order_type(), request_quotation_type())),
2370 2309
          disabled  => !$may_edit_create ? t8('You do not have the permissions to access this function.') : undef,
js/kivi.Order.js
782 782
    kivi.SalesPurchase.edit_custom_shipto();
783 783
  };
784 784

  
785
  ns.purchase_order_check_for_direct_delivery = function() {
785
  ns.purchase_order_check_for_direct_delivery = function(params) {
786
    const to_type = params.to_type;
787

  
786 788
    if ($('#type').val() != 'sales_order') {
787
      kivi.submit_ajax_form("controller.pl", '#order_form', {action: 'Order/save_and_purchase_order'});
789
      kivi.submit_ajax_form("controller.pl", '#order_form', {action: 'Order/save_and_order_workflow', to_type: to_type});
788 790
      return;
789 791
    }
790 792

  
......
813 815

  
814 816
    var use_it = false;
815 817
    if (!empty) {
816
      ns.direct_delivery_dialog(shipto);
818
      ns.direct_delivery_dialog(shipto, to_type);
817 819
    } else {
818
      kivi.submit_ajax_form("controller.pl", '#order_form', {action: 'Order/save_and_purchase_order'});
820
      kivi.submit_ajax_form("controller.pl", '#order_form', {action: 'Order/save_and_order_workflow', to_type: to_type});
819 821
    }
820 822
  };
821 823

  
822
  ns.direct_delivery_callback = function(accepted) {
824
  ns.direct_delivery_callback = function(accepted, to_type) {
823 825
    $('#direct-delivery-dialog').dialog('close');
824 826

  
825 827
    if (accepted) {
826 828
      $('<input type="hidden" name="use_shipto">').appendTo('#order_form').val('1');
827 829
    }
828 830

  
829
    kivi.submit_ajax_form("controller.pl", '#order_form', {action: 'Order/save_and_purchase_order'});
831
    kivi.submit_ajax_form("controller.pl", '#order_form', {action: 'Order/save_and_order_workflow', to_type: to_type});
830 832
  };
831 833

  
832
  ns.direct_delivery_dialog = function(shipto) {
834
  ns.direct_delivery_dialog = function(shipto, to_type) {
833 835
    $('#direct-delivery-dialog').remove();
834 836

  
835 837
    var text1 = kivi.t8('You have entered or selected the following shipping address for this customer:');
836 838
    var text2 = kivi.t8('Do you want to carry this shipping address over to the new purchase order so that the vendor can deliver the goods directly to your customer?');
837 839
    var html  = '<div id="direct-delivery-dialog"><p>' + text1 + '</p><p>' + shipto + '</p><p>' + text2 + '</p>';
838 840
    html      = html + '<hr><p>';
839
    html      = html + '<input type="button" value="' + kivi.t8('Yes') + '" size="30" onclick="kivi.Order.direct_delivery_callback(true)">';
841
    html      = html + '<input type="button" value="' + kivi.t8('Yes') + '" size="30" onclick="kivi.Order.direct_delivery_callback(true,  \'' + to_type + '\')">';
840 842
    html      = html + '&nbsp;';
841
    html      = html + '<input type="button" value="' + kivi.t8('No')  + '" size="30" onclick="kivi.Order.direct_delivery_callback(false)">';
843
    html      = html + '<input type="button" value="' + kivi.t8('No')  + '" size="30" onclick="kivi.Order.direct_delivery_callback(false, \'' + to_type + '\')">';
842 844
    html      = html + '</p></div>';
843 845
    $(html).hide().appendTo('#order_form');
844 846

  

Auch abrufbar als: Unified diff