From 9ce44b6f09f77fc51a69e4536fa44dee68d0ab85 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Bernd=20Ble=C3=9Fmann?= Date: Mon, 20 Sep 2021 10:57:36 +0200 Subject: [PATCH] =?utf8?q?Auftrags-Controller:=20Warnung=20bei=20fehlendem?= =?utf8?q?=20Transportkosten-Artikel=20=E2=80=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit bei VK-Angebot und -Auftrag, wenn in der Mandanten-Konfiguration angegeben. --- SL/Controller/Order.pm | 34 ++++++++++++++++++++---------- js/kivi.Order.js | 17 +++++++++++++++ templates/webpages/order/form.html | 4 +++- 3 files changed, 43 insertions(+), 12 deletions(-) diff --git a/SL/Controller/Order.pm b/SL/Controller/Order.pm index ae8c8dea6..284e200ab 100644 --- a/SL/Controller/Order.pm +++ b/SL/Controller/Order.pm @@ -1873,6 +1873,11 @@ sub pre_render { } } @all_objects; } + if ( (any { $self->type eq $_ } (sales_quotation_type(), sales_order_type())) + && $::instance_conf->get_transport_cost_reminder_article_number_id ) { + $self->{template_args}->{transport_cost_reminder_article} = SL::DB::Part->new(id => $::instance_conf->get_transport_cost_reminder_article_number_id)->load; + } + $self->get_item_cvpartnumber($_) for @{$self->order->items_sorted}; $::request->{layout}->use_javascript("${_}.js") for qw(kivi.SalesPurchase kivi.Order kivi.File ckeditor/ckeditor ckeditor/adapters/jquery @@ -1887,6 +1892,8 @@ sub setup_edit_action_bar { || (($self->type eq sales_order_type()) && $::instance_conf->get_sales_order_show_delete) || (($self->type eq purchase_order_type()) && $::instance_conf->get_purchase_order_show_delete); + my @req_trans_cost_art = qw(kivi.Order.check_transport_cost_article_presence) x!!$::instance_conf->get_transport_cost_reminder_article_number_id; + for my $bar ($::request->layout->get('actionbar')) { $bar->add( combobox => [ @@ -1895,12 +1902,12 @@ sub setup_edit_action_bar { call => [ 'kivi.Order.save', 'save', $::instance_conf->get_order_warn_duplicate_parts, $::instance_conf->get_order_warn_no_deliverydate, ], - checks => [ 'kivi.Order.check_save_active_periodic_invoices', ['kivi.validate_form','#order_form'] ], + checks => [ 'kivi.Order.check_save_active_periodic_invoices', ['kivi.validate_form','#order_form'], @req_trans_cost_art ], ], action => [ t8('Save as new'), call => [ 'kivi.Order.save', 'save_as_new', $::instance_conf->get_order_warn_duplicate_parts ], - checks => [ 'kivi.Order.check_save_active_periodic_invoices' ], + checks => [ 'kivi.Order.check_save_active_periodic_invoices', @req_trans_cost_art ], disabled => !$self->order->id ? t8('This object has not been saved yet.') : undef, ], ], # end of combobox "Save" @@ -1912,6 +1919,7 @@ sub setup_edit_action_bar { action => [ t8('Save and Quotation'), submit => [ '#order_form', { action => "Order/sales_quotation" } ], + checks => [ @req_trans_cost_art ], only_if => (any { $self->type eq $_ } (sales_order_type())), ], action => [ @@ -1922,11 +1930,13 @@ sub setup_edit_action_bar { action => [ t8('Save and Sales Order'), submit => [ '#order_form', { action => "Order/sales_order" } ], + checks => [ @req_trans_cost_art ], only_if => (any { $self->type eq $_ } (sales_quotation_type(), purchase_order_type())), ], action => [ t8('Save and Purchase Order'), call => [ 'kivi.Order.purchase_order_check_for_direct_delivery' ], + checks => [ @req_trans_cost_art ], only_if => (any { $self->type eq $_ } (sales_order_type(), request_quotation_type())), ], action => [ @@ -1934,13 +1944,13 @@ sub setup_edit_action_bar { call => [ 'kivi.Order.save', 'save_and_delivery_order', $::instance_conf->get_order_warn_duplicate_parts, $::instance_conf->get_order_warn_no_deliverydate, ], - checks => [ 'kivi.Order.check_save_active_periodic_invoices' ], + checks => [ 'kivi.Order.check_save_active_periodic_invoices', @req_trans_cost_art ], only_if => (any { $self->type eq $_ } (sales_order_type(), purchase_order_type())) ], action => [ t8('Save and Invoice'), call => [ 'kivi.Order.save', 'save_and_invoice', $::instance_conf->get_order_warn_duplicate_parts ], - checks => [ 'kivi.Order.check_save_active_periodic_invoices' ], + checks => [ 'kivi.Order.check_save_active_periodic_invoices', @req_trans_cost_art ], ], action => [ t8('Save and AP Transaction'), @@ -1956,15 +1966,17 @@ sub setup_edit_action_bar { ], action => [ t8('Save and preview PDF'), - call => [ 'kivi.Order.save', 'preview_pdf', $::instance_conf->get_order_warn_duplicate_parts, - $::instance_conf->get_order_warn_no_deliverydate, - ], + call => [ 'kivi.Order.save', 'preview_pdf', $::instance_conf->get_order_warn_duplicate_parts, + $::instance_conf->get_order_warn_no_deliverydate, + ], + checks => [ @req_trans_cost_art ], ], action => [ t8('Save and print'), - call => [ 'kivi.Order.show_print_options', $::instance_conf->get_order_warn_duplicate_parts, - $::instance_conf->get_order_warn_no_deliverydate, - ], + call => [ 'kivi.Order.show_print_options', $::instance_conf->get_order_warn_duplicate_parts, + $::instance_conf->get_order_warn_no_deliverydate, + ], + checks => [ @req_trans_cost_art ], ], action => [ t8('Save and E-mail'), @@ -2416,7 +2428,7 @@ java script functions =item * optional client/user behaviour (transactions has to be set - department has to be set - - force project if enabled in client config - transport cost reminder) + force project if enabled in client config) =back diff --git a/js/kivi.Order.js b/js/kivi.Order.js index a96f49f7f..140eba2f0 100644 --- a/js/kivi.Order.js +++ b/js/kivi.Order.js @@ -844,6 +844,23 @@ namespace('kivi.Order', function(ns) { $.post("controller.pl", data, kivi.eval_json_result); }; + ns.check_transport_cost_article_presence = function() { + var $form = $('#order_form'); + var wanted_part_id = $form.data('transport-cost-reminder-article-id'); + + if (!wanted_part_id) return true + + var id_arr = $('[name="order.orderitems[].parts_id"]').map(function() { return this.value; }).get(); + id_arr = $.grep(id_arr, function(elt) { + return ((elt*1) === wanted_part_id); + }); + + if (id_arr.length) return true; + + var description = $form.data('transport-cost-reminder-article-description'); + return confirm(kivi.t8("The transport cost article '#1' is missing. Do you want to continue anyway?", [ description ])); + }; + }); $(function() { diff --git a/templates/webpages/order/form.html b/templates/webpages/order/form.html index c3ff986aa..17534de23 100644 --- a/templates/webpages/order/form.html +++ b/templates/webpages/order/form.html @@ -15,7 +15,9 @@ -
+ [% L.hidden_tag('callback', FORM.callback) %] [% L.hidden_tag('type', FORM.type) %] [% L.hidden_tag('id', SELF.order.id) %] -- 2.20.1