Kreditorenbuchungen: Zahlungsbedingungen laden/speichern
authorSven Schöling <s.schoeling@googlemail.com>
Thu, 3 Dec 2020 15:41:51 +0000 (16:41 +0100)
committerSven Schöling <s.schoeling@googlemail.com>
Thu, 3 Dec 2020 16:01:16 +0000 (17:01 +0100)
bin/mozilla/ap.pl
templates/webpages/ap/form_header.html

index 2fe8041..8e9e4ca 100644 (file)
@@ -48,6 +48,7 @@ use SL::DB::Chart;
 use SL::DB::Currency;
 use SL::DB::Default;
 use SL::DB::Order;
+use SL::DB::PaymentTerm;
 use SL::DB::PurchaseInvoice;
 use SL::DB::RecordTemplate;
 use SL::DB::Tax;
@@ -252,7 +253,12 @@ sub add {
   $form->{transdate} = $form->{initial_transdate};
 
   if ($form->{vendor_id}) {
-    my $last_used_ap_chart = SL::DB::Vendor->load_cached($form->{vendor_id})->last_used_ap_chart;
+    my $vendor = SL::DB::Vendor->load_cached($form->{vendor_id});
+
+    # set initial payment terms
+    $form->{payment_id} = $vendor->payment_id;
+
+    my $last_used_ap_chart = $vendor->last_used_ap_chart;
     $form->{"AP_amount_chart_id_1"} = $last_used_ap_chart->id if $last_used_ap_chart;
   }
 
@@ -556,6 +562,7 @@ sub form_header {
   print $form->parse_html_template('ap/form_header', {
     today => DateTime->today,
     currencies => SL::DB::Manager::Currency->get_all_sorted,
+    payment_terms => SL::DB::Manager::PaymentTerm->get_all_sorted(query => [ or => [ obsolete => 0, id => $::form->{payment_id}*1 ]]),
   });
 
   $main::lxdebug->leave_sub();
@@ -656,8 +663,14 @@ sub update {
 
   if (($form->{previous_vendor_id} || $form->{vendor_id}) != $form->{vendor_id}) {
     IR->get_vendor(\%::myconfig, $form);
+
+    my $vendor = SL::DB::Vendor->load_cached($form->{vendor_id});
+
+    # reset payment to new vendor
+    $form->{payment_id} = $vendor->payment_id;
+
     if (($form->{rowcount} == 1) && ($form->{amount_1} == 0)) {
-      my $last_used_ap_chart = SL::DB::Vendor->load_cached($form->{vendor_id})->last_used_ap_chart;
+      my $last_used_ap_chart = $vendor->last_used_ap_chart;
       $form->{"AP_amount_chart_id_1"} = $last_used_ap_chart->id if $last_used_ap_chart;
     }
   }
index a332733..1c5a51d 100644 (file)
           <tr>
            <th align="left">[% 'Notes' | $T8 %]</th>
            <th align="left">[% 'Internal Notes' | $T8 %]</th>
+           <th align="left">[% 'Payment Terms' | $T8 %]</th>
           </tr>
           <tr valign="top">
            <td>
            <td>
             [% L.textarea_tag("intnotes", intnotes, wrap="soft", rows=textarea_rows, cols=50, readonly=readonly) %]
            </td>
+           <td>
+             [% L.select_tag('payment_id', payment_terms, default=payment_id, title_key='description', with_empty=1, style="width: 250px") %]
+           </td>
           <tr>
         </table>
     </td>