Zeiterfassung: Auftrag auswählen können, Kunden und ggf. Projekt daraus setzen
authorBernd Bleßmann <bernd@kivitendo-premium.de>
Thu, 29 Apr 2021 12:19:46 +0000 (14:19 +0200)
committerBernd Bleßmann <bernd@kivitendo-premium.de>
Wed, 5 May 2021 15:25:03 +0000 (17:25 +0200)
Auftrag hat Vorrang und setzt Kunde und Projekt. Diese Felder sind dann
gesperrt.
Wenn kein Auftrag gewählt ist (oder einer wieder abgtewählt wird,
dann ist Kunde und Projekt wieder frei.

SL/Controller/TimeRecording.pm
js/kivi.TimeRecording.js
templates/webpages/time_recording/form.html

index ed1d9b9..709b6b6 100644 (file)
@@ -11,6 +11,7 @@ use SL::Controller::Helper::GetModels;
 use SL::Controller::Helper::ReportGenerator;
 use SL::DB::Customer;
 use SL::DB::Employee;
+use SL::DB::Order;
 use SL::DB::Part;
 use SL::DB::TimeRecording;
 use SL::DB::TimeRecordingArticle;
@@ -22,7 +23,7 @@ use SL::ReportGenerator;
 use Rose::Object::MakeMethods::Generic
 (
 # scalar                  => [ qw() ],
- 'scalar --get_set_init' => [ qw(time_recording models all_employees all_time_recording_articles can_view_all can_edit_all use_duration) ],
+ 'scalar --get_set_init' => [ qw(time_recording models all_employees all_time_recording_articles all_orders can_view_all can_edit_all use_duration) ],
 );
 
 
@@ -119,6 +120,21 @@ sub action_delete {
   $self->redirect_to(safe_callback());
 }
 
+sub action_ajaj_get_order_info {
+
+  my $order = SL::DB::Order->new(id => $::form->{id})->load;
+  my $data  = { customer => { id    => $order->customer_id,
+                              value => $order->customer->displayable_name,
+                              type  => 'customer'
+                },
+                project => { id     =>  $order->globalproject_id,
+                             value  => ($order->globalproject_id ? $order->globalproject->displayable_name : undef),
+                },
+  };
+
+  $_[0]->render(\SL::JSON::to_json($data), { type => 'json', process => 0 });
+}
+
 sub init_time_recording {
   my ($self) = @_;
 
@@ -196,6 +212,11 @@ sub init_all_time_recording_articles {
   return $res;
 }
 
+sub init_all_orders {
+  SL::DB::Manager::Order->get_all_sorted(query => [or             => [ closed => 0, closed => undef ],
+                                                   '!customer_id' => undef]);
+}
+
 sub init_use_duration {
   return SL::Helper::UserPreferences::TimeRecording->new()->get_use_duration();
 }
index cf50149..f5cf3c8 100644 (file)
@@ -19,4 +19,22 @@ namespace('kivi.TimeRecording', function(ns) {
     $time.val(kivi.format_time(date));
   };
 
+  ns.order_changed = function(value) {
+    if (!value) {
+      $('#time_recording_customer_id').data('customer_vendor_picker').set_item({});
+      $('#time_recording_customer_id_name').prop('disabled', false);
+      $('#time_recording_project_id').data('project_picker').set_item({});
+      $('#time_recording_project_id_name').prop('disabled', false);
+        return;
+    }
+
+    var url = 'controller.pl?action=TimeRecording/ajaj_get_order_info&id='+ value;
+    $.getJSON(url, function(data) {
+      $('#time_recording_customer_id').data('customer_vendor_picker').set_item(data.customer);
+      $('#time_recording_customer_id_name').prop('disabled', true);
+      $('#time_recording_project_id').data('project_picker').set_item(data.project);
+      $('#time_recording_project_id_name').prop('disabled', true);
+    });
+  };
+
 });
index 99e9c0f..7c2e3d5 100644 (file)
@@ -22,6 +22,7 @@
         <th>[% 'Start' | $T8 %]</th>
         <th>[% 'End'   | $T8 %]</th>
        [%- END %]
+        <th>[% 'Sales Order' | $T8 %]</th>
         <th>[% 'Customer' | $T8 %]</th>
         <th>[% 'Article' | $T8 %]</th>
         <th>[% 'Project' | $T8 %]</th>
@@ -50,6 +51,7 @@
           [% P.button_tag('kivi.TimeRecording.set_current_date_time("end")', LxERP.t8('now')) %]
         </td>
        [%- END %]
+        <td>[% P.select_tag('time_recording.order_id', SELF.all_orders, default=SELF.time_recording.order_id, title_key='digest', with_empty=1, onchange='kivi.TimeRecording.order_changed(this.value)') %]</td>
         <td>[% P.customer_vendor.picker('time_recording.customer_id', SELF.time_recording.customer_id, type='customer', style='width: 300px', "data-validate"="required", "data-title"=LxERP.t8('Customer')) %]</td>
         <td>[% P.select_tag('time_recording.part_id', SELF.all_time_recording_articles, default=SELF.time_recording.part_id, with_empty=1, value_key='id', title_key='description') %]</td>
         <td>[% P.project.picker('time_recording.project_id', SELF.time_recording.project_id, style='width: 300px') %]</td>