1 #=====================================================================
4 # Based on SQL-Ledger Version 2.1.9
5 # Web http://www.lx-office.org
7 #=====================================================================
8 # SQL-Ledger Accounting
11 # Author: Dieter Simader
12 # Email: dsimader@sql-ledger.org
13 # Web: http://www.sql-ledger.org
16 # This program is free software; you can redistribute it and/or modify
17 # it under the terms of the GNU General Public License as published by
18 # the Free Software Foundation; either version 2 of the License, or
19 # (at your option) any later version.
21 # This program is distributed in the hope that it will be useful,
22 # but WITHOUT ANY WARRANTY; without even the implied warranty of
23 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24 # GNU General Public License for more details.
25 # You should have received a copy of the GNU General Public License
26 # along with this program; if not, write to the Free Software
27 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
29 #======================================================================
31 # Accounts Receivables
33 #======================================================================
35 use POSIX qw(strftime);
36 use List::Util qw(sum first max);
37 use List::UtilsBy qw(sort_by);
40 use SL::Controller::Base;
50 use SL::DB::RecordTemplate;
52 use SL::Helper::Flash qw(flash);
53 use SL::Locale::String qw(t8);
54 use SL::ReportGenerator;
56 require "bin/mozilla/common.pl";
57 require "bin/mozilla/reportgenerator.pl";
62 # this is for our long dates
63 # $locale->text('January')
64 # $locale->text('February')
65 # $locale->text('March')
66 # $locale->text('April')
67 # $locale->text('May ')
68 # $locale->text('June')
69 # $locale->text('July')
70 # $locale->text('August')
71 # $locale->text('September')
72 # $locale->text('October')
73 # $locale->text('November')
74 # $locale->text('December')
76 # this is for our short month
77 # $locale->text('Jan')
78 # $locale->text('Feb')
79 # $locale->text('Mar')
80 # $locale->text('Apr')
81 # $locale->text('May')
82 # $locale->text('Jun')
83 # $locale->text('Jul')
84 # $locale->text('Aug')
85 # $locale->text('Sep')
86 # $locale->text('Oct')
87 # $locale->text('Nov')
88 # $locale->text('Dec')
90 sub load_record_template {
91 $::auth->assert('ar_transactions');
93 # Load existing template and verify that its one for this module.
94 my $template = SL::DB::RecordTemplate
95 ->new(id => $::form->{id})
97 with_object => [ qw(customer payment currency record_items record_items.chart) ],
100 die "invalid template type" unless $template->template_type eq 'ar_transaction';
102 $template->substitute_variables;
104 # Clean the current $::form before rebuilding it from the template.
105 my $form_defaults = delete $::form->{form_defaults};
106 delete @{ $::form }{ grep { !m{^(?:script|login)$}i } keys %{ $::form } };
108 # Fill $::form from the template.
109 my $today = DateTime->today_local;
110 $::form->{title} = "Add";
111 $::form->{currency} = $template->currency->name;
112 $::form->{direct_debit} = $template->direct_debit;
113 $::form->{globalproject_id} = $template->project_id;
114 $::form->{AR_chart_id} = $template->ar_ap_chart_id;
115 $::form->{transdate} = $today->to_kivitendo;
116 $::form->{duedate} = $today->to_kivitendo;
117 $::form->{rowcount} = @{ $template->items };
118 $::form->{paidaccounts} = 1;
119 $::form->{$_} = $template->$_ for qw(department_id ordnumber taxincluded employee_id notes);
121 if ($template->customer) {
122 $::form->{customer_id} = $template->customer_id;
123 $::form->{customer} = $template->customer->name;
124 $::form->{duedate} = $template->customer->payment->calc_date(reference_date => $today)->to_kivitendo if $template->customer->payment;
128 foreach my $item (@{ $template->items }) {
131 my $active_taxkey = $item->chart->get_active_taxkey;
132 my $taxes = SL::DB::Manager::Tax->get_all(
133 where => [ chart_categories => { like => '%' . $item->chart->category . '%' }],
134 sort_by => 'taxkey, rate',
137 my $tax = first { $item->tax_id == $_->id } @{ $taxes };
138 $tax //= first { $active_taxkey->tax_id == $_->id } @{ $taxes };
139 $tax //= $taxes->[0];
146 $::form->{"AR_amount_chart_id_${row}"} = $item->chart_id;
147 $::form->{"previous_AR_amount_chart_id_${row}"} = $item->chart_id;
148 $::form->{"amount_${row}"} = $::form->format_amount(\%::myconfig, $item->amount1, 2);
149 $::form->{"taxchart_${row}"} = $item->tax_id . '--' . $tax->rate;
150 $::form->{"project_id_${row}"} = $item->project_id;
153 $::form->{$_} = $form_defaults->{$_} for keys %{ $form_defaults // {} };
155 flash('info', $::locale->text("The record template '#1' has been loaded.", $template->template_name));
158 keep_rows_without_amount => 1,
159 dont_add_new_row => 1,
163 sub save_record_template {
164 $::auth->assert('ar_transactions');
166 my $template = $::form->{record_template_id} ? SL::DB::RecordTemplate->new(id => $::form->{record_template_id})->load : SL::DB::RecordTemplate->new;
167 my $js = SL::ClientJS->new(controller => SL::Controller::Base->new);
168 my $new_name = $template->template_name_to_use($::form->{record_template_new_template_name});
170 $js->dialog->close('#record_template_dialog');
173 $_->{chart_id} && (($_->{tax_id} // '') ne '')
175 +{ chart_id => $::form->{"AR_amount_chart_id_${_}"},
176 amount1 => $::form->parse_amount(\%::myconfig, $::form->{"amount_${_}"}),
177 tax_id => (split m{--}, $::form->{"taxchart_${_}"})[0],
178 project_id => $::form->{"project_id_${_}"} || undef,
180 } (1..($::form->{rowcount} || 1));
182 $template->assign_attributes(
183 template_type => 'ar_transaction',
184 template_name => $new_name,
186 currency_id => SL::DB::Manager::Currency->find_by(name => $::form->{currency})->id,
187 ar_ap_chart_id => $::form->{AR_chart_id} || undef,
188 customer_id => $::form->{customer_id} || undef,
189 department_id => $::form->{department_id} || undef,
190 project_id => $::form->{globalproject_id} || undef,
191 employee_id => $::form->{employee_id} || undef,
192 taxincluded => $::form->{taxincluded} ? 1 : 0,
193 direct_debit => $::form->{direct_debit} ? 1 : 0,
194 ordnumber => $::form->{ordnumber},
195 notes => $::form->{notes},
205 ->flash('error', $::locale->text("Saving the record template '#1' failed.", $new_name))
210 ->flash('info', $::locale->text("The record template '#1' has been saved.", $new_name))
215 $main::lxdebug->enter_sub();
217 $main::auth->assert('ar_transactions');
219 my $form = $main::form;
220 my %myconfig = %main::myconfig;
223 if(!exists $form->{addition} && ($form->{id} ne "")) {
224 $form->{snumbers} = qq|invnumber_| . $form->{invnumber};
225 $form->{addition} = "ADDED";
228 # /saving the history
230 $form->{title} = "Add";
231 $form->{callback} = "ar.pl?action=add" unless $form->{callback};
233 AR->get_transdate(\%myconfig, $form);
234 $form->{initial_transdate} = $form->{transdate};
235 create_links(dont_save => 1);
236 $form->{transdate} = $form->{initial_transdate};
238 if ($form->{customer_id}) {
239 my $last_used_ar_chart = SL::DB::Customer->load_cached($form->{customer_id})->last_used_ar_chart;
240 $form->{"AR_amount_chart_id_1"} = $last_used_ar_chart->id if $last_used_ar_chart;
244 $main::lxdebug->leave_sub();
248 $main::lxdebug->enter_sub();
250 $main::auth->assert('ar_transactions');
252 my $form = $main::form;
254 # show history button
255 $form->{javascript} = qq|<script type="text/javascript" src="js/show_history.js"></script>|;
256 #/show hhistory button
257 $form->{javascript} .= qq|<script type="text/javascript" src="js/common.js"></script>|;
258 $form->{title} = "Edit";
263 $main::lxdebug->leave_sub();
267 $main::lxdebug->enter_sub();
269 $main::auth->assert('ar_transactions');
271 my $form = $main::form;
276 $main::lxdebug->leave_sub();
279 sub _retrieve_invoice_object {
280 return undef if !$::form->{id};
281 return $::form->{invoice_obj} if $::form->{invoice_obj} && $::form->{invoice_obj}->id == $::form->{id};
282 return SL::DB::Invoice->new(id => $::form->{id})->load;
286 $main::lxdebug->enter_sub();
288 $main::auth->assert('ar_transactions');
291 my $form = $main::form;
292 my %myconfig = %main::myconfig;
294 $form->create_links("AR", \%myconfig, "customer");
295 $form->{invoice_obj} = _retrieve_invoice_object();
298 if (!$params{dont_save}) {
299 %saved = map { ($_ => $form->{$_}) } qw(direct_debit id taxincluded);
300 $saved{duedate} = $form->{duedate} if $form->{duedate};
301 $saved{currency} = $form->{currency} if $form->{currency};
304 IS->get_customer(\%myconfig, \%$form);
306 $form->{$_} = $saved{$_} for keys %saved;
307 $form->{rowcount} = 1;
308 $form->{AR_chart_id} = $form->{acc_trans} && $form->{acc_trans}->{AR} ? $form->{acc_trans}->{AR}->[0]->{chart_id} : $form->{AR_links}->{AR}->[0]->{chart_id};
311 $form->{defaultcurrency} = $form->get_default_currency(\%myconfig);
313 $form->{ALL_DEPARTMENTS} = SL::DB::Manager::Department->get_all;
315 # build the popup menus
316 $form->{taxincluded} = ($form->{id}) ? $form->{taxincluded} : "checked";
318 AR->setup_form($form);
321 ($form->datetonum($form->{transdate}, \%myconfig) <=
322 $form->datetonum($form->{closedto}, \%myconfig));
324 $main::lxdebug->leave_sub();
328 $main::lxdebug->enter_sub();
330 $main::auth->assert('ar_transactions');
332 my $form = $main::form;
333 my %myconfig = %main::myconfig;
334 my $locale = $main::locale;
335 my $cgi = $::request->{cgi};
337 $form->{invoice_obj} = _retrieve_invoice_object();
339 my ($title, $readonly, $exchangerate, $rows);
340 my ($notes, $amount, $project);
342 $form->{initial_focus} = !($form->{amount_1} * 1) ? 'customer_id' : 'row_' . $form->{rowcount};
344 $title = $form->{title};
345 # $locale->text('Add Accounts Receivables Transaction')
346 # $locale->text('Edit Accounts Receivables Transaction')
347 $form->{title} = $locale->text("$title Accounts Receivables Transaction");
349 $readonly = ($form->{id}) ? "readonly" : "";
351 $form->{radier} = ($::instance_conf->get_ar_changeable == 2)
352 ? ($form->current_date(\%myconfig) eq $form->{gldate})
353 : ($::instance_conf->get_ar_changeable == 1);
354 $readonly = ($form->{radier}) ? "" : $readonly;
356 $form->{forex} = $form->check_exchangerate( \%myconfig, $form->{currency}, $form->{transdate}, 'buy');
357 $form->{exchangerate} = $form->{forex} if $form->{forex};
359 # format exchangerate
360 $form->{exchangerate} = $form->{exchangerate} ? $form->format_amount(\%myconfig, $form->{exchangerate}) : '';
362 $rows = max 2, $form->numtextrows($form->{notes}, 50);
364 my @old_project_ids = grep { $_ } map { $form->{"project_id_$_"} } 1..$form->{rowcount};
366 $form->get_lists("projects" => { "key" => "ALL_PROJECTS",
368 "old_id" => \@old_project_ids },
369 "charts" => { "key" => "ALL_CHARTS",
370 "transdate" => $form->{transdate} },
371 "taxcharts" => { "key" => "ALL_TAXCHARTS",
372 "module" => "AR" },);
374 $form->{ALL_DEPARTMENTS} = SL::DB::Manager::Department->get_all;
376 $_->{link_split} = { map { $_ => 1 } split/:/, $_->{link} } for @{ $form->{ALL_CHARTS} };
378 my %project_labels = map { $_->{id} => $_->{projectnumber} } @{ $form->{"ALL_PROJECTS"} };
380 my (@AR_paid_values, %AR_paid_labels);
381 my $default_ar_amount_chart_id;
383 foreach my $item (@{ $form->{ALL_CHARTS} }) {
384 if ($item->{link_split}{AR_amount}) {
385 $default_ar_amount_chart_id //= $item->{id};
387 } elsif ($item->{link_split}{AR_paid}) {
388 push(@AR_paid_values, $item->{accno});
389 $AR_paid_labels{$item->{accno}} = "$item->{accno}--$item->{description}";
393 my $follow_up_vc = $form->{customer_id} ? SL::DB::Customer->load_cached($form->{customer_id})->name : '';
394 my $follow_up_trans_info = "$form->{invnumber} ($follow_up_vc)";
396 $::request->layout->add_javascripts("autocomplete_chart.js", "autocomplete_customer.js", "show_vc_details.js", "show_history.js", "follow_up.js", "kivi.Draft.js", "kivi.GL.js", "kivi.File.js", "kivi.RecordTemplate.js", "kivi.AR.js");
398 my $transdate = $::form->{transdate} ? DateTime->from_kivitendo($::form->{transdate}) : DateTime->today_local;
402 for my $i (1 .. $form->{rowcount}) {
404 amount => $form->{"amount_$i"},
405 tax => $form->{"tax_$i"},
406 project_id => ($i==$form->{rowcount}) ? $form->{globalproject_id} : $form->{"project_id_$i"},
409 my (%taxchart_labels, @taxchart_values, $default_taxchart, $taxchart_to_use);
410 my $amount_chart_id = $form->{"AR_amount_chart_id_$i"} // $default_ar_amount_chart_id;
411 my $chart_has_changed = $::form->{"previous_AR_amount_chart_id_$i"} && ($amount_chart_id != $::form->{"previous_AR_amount_chart_id_$i"});
413 foreach my $item ( GL->get_active_taxes_for_chart($amount_chart_id, $transdate) ) {
414 my $key = $item->id . "--" . $item->rate;
415 $first_taxchart //= $item;
416 $default_taxchart = $item if $item->{is_default};
417 $taxchart_to_use = $item if $key eq $form->{"taxchart_$i"};
419 push(@taxchart_values, $key);
420 $taxchart_labels{$key} = $item->taxdescription . " " . $item->rate * 100 . ' %';
423 $taxchart_to_use = $default_taxchart // $first_taxchart if $chart_has_changed || !$taxchart_to_use;
424 my $selected_taxchart = $taxchart_to_use->id . '--' . $taxchart_to_use->rate;
426 $transaction->{selectAR_amount} =
427 $::request->presenter->chart_picker("AR_amount_chart_id_$i", $amount_chart_id, style => "width: 400px", type => "AR_amount", class => ($form->{initial_focus} eq "row_$i" ? "initial_focus" : ""))
428 . $::request->presenter->hidden_tag("previous_AR_amount_chart_id_$i", $amount_chart_id);
430 $transaction->{taxchart} =
431 NTI($cgi->popup_menu('-name' => "taxchart_$i",
432 '-id' => "taxchart_$i",
433 '-style' => 'width:200px',
434 '-values' => \@taxchart_values,
435 '-labels' => \%taxchart_labels,
436 '-default' => $selected_taxchart));
438 push @transactions, $transaction;
441 $form->{invtotal_unformatted} = $form->{invtotal};
443 $form->{paidaccounts}++ if ($form->{"paid_$form->{paidaccounts}"});
445 my $now = $form->current_date(\%myconfig);
448 for my $i (1 .. $form->{paidaccounts}) {
450 paid => $form->{"paid_$i"},
451 exchangerate => $form->{"exchangerate_$i"} || '',
452 gldate => $form->{"gldate_$i"},
453 acc_trans_id => $form->{"acc_trans_id_$i"},
454 source => $form->{"source_$i"},
455 memo => $form->{"memo_$i"},
456 AR_paid => $form->{"AR_paid_$i"},
457 forex => $form->{"forex_$i"},
458 datepaid => $form->{"datepaid_$i"},
459 paid_project_id => $form->{"paid_project_id_$i"},
460 gldate => $form->{"gldate_$i"},
463 # default account for current assets (i.e. 1801 - SKR04) if no account is selected
464 $form->{accno_arap} = IS->get_standard_accno_current_assets(\%myconfig, \%$form);
466 $payment->{selectAR_paid} =
467 NTI($cgi->popup_menu('-name' => "AR_paid_$i",
468 '-id' => "AR_paid_$i",
469 '-values' => \@AR_paid_values,
470 '-labels' => \%AR_paid_labels,
471 '-default' => $payment->{AR_paid} || $form->{accno_arap}));
475 $payment->{changeable} =
476 SL::DB::Default->get->payments_changeable == 0 ? !$payment->{acc_trans_id} # never
477 : SL::DB::Default->get->payments_changeable == 2 ? $payment->{gldate} eq '' || $payment->{gldate} eq $now
480 #deaktivieren von gebuchten Zahlungen ausserhalb der BĂ¼cherkontrolle, vorher prĂ¼fen ob heute eingegeben
481 if ($form->date_closed($payment->{"gldate_$i"})) {
482 $payment->{changeable} = 0;
485 push @payments, $payment;
488 my @empty = grep { $_->{paid} eq '' } @payments;
490 (sort_by { DateTime->from_kivitendo($_->{datepaid}) } grep { $_->{paid} ne '' } @payments),
494 $form->{totalpaid} = sum map { $_->{paid} } @payments;
496 my $employees = SL::DB::Manager::Employee->get_all_sorted(
499 (id => $::form->{employee_id}) x !!$::form->{employee_id},
506 setup_ar_form_header_action_bar();
509 print $::form->parse_html_template('ar/form_header', {
510 paid_missing => $::form->{invtotal} - $::form->{totalpaid},
511 show_exch => ($::form->{defaultcurrency} && ($::form->{currency} ne $::form->{defaultcurrency})),
512 payments => \@payments,
513 transactions => \@transactions,
514 project_labels => \%project_labels,
516 AR_chart_id => $form->{AR_chart_id},
518 follow_up_trans_info => $follow_up_trans_info,
519 today => DateTime->today,
520 currencies => scalar(SL::DB::Manager::Currency->get_all_sorted),
521 employees => $employees,
524 $main::lxdebug->leave_sub();
528 $main::lxdebug->enter_sub();
530 $main::auth->assert('ar_transactions');
532 my $form = $main::form;
533 my %myconfig = %main::myconfig;
534 my $locale = $main::locale;
535 my $cgi = $::request->{cgi};
538 my $follow_ups = FU->follow_ups('trans_id' => $form->{id}, 'not_done' => 1);
539 if ( @{ $follow_ups} ) {
540 $form->{follow_up_length} = scalar(@{$follow_ups});
541 $form->{follow_up_due_length} = sum(map({ $_->{due} * 1 } @{ $follow_ups }));
545 print $::form->parse_html_template('ar/form_footer');
547 $main::lxdebug->leave_sub();
551 $::auth->assert('ar_transactions');
553 SL::DB::Invoice->new(id => $::form->{id})->load->mark_as_paid;
554 $::form->redirect($::locale->text("Marked as paid"));
558 $::form->{transdate} = DateTime->today_local->to_kivitendo if !$::form->{transdate};
559 $::form->{gldate} = $::form->{transdate} if !$::form->{gldate};
565 $main::lxdebug->enter_sub();
567 $main::auth->assert('ar_transactions');
569 my $form = $main::form;
570 my %myconfig = %main::myconfig;
574 my ($totaltax, $exchangerate);
576 $form->{invtotal} = 0;
578 delete @{ $form }{ grep { m/^tax_\d+$/ } keys %{ $form } };
580 map { $form->{$_} = $form->parse_amount(\%myconfig, $form->{$_}) }
581 qw(exchangerate creditlimit creditremaining);
583 my @flds = qw(amount AR_amount projectnumber oldprojectnumber project_id);
587 for my $i (1 .. $form->{rowcount}) {
588 $form->{"amount_$i"} = $form->parse_amount(\%myconfig, $form->{"amount_$i"});
589 if ($form->{"amount_$i"} || $params{keep_rows_without_amount}) {
592 my ($taxkey, $rate) = split(/--/, $form->{"taxchart_$i"});
595 ($tmpnetamount,$form->{"tax_$i"}) = $form->calculate_tax($form->{"amount_$i"},$rate,$form->{taxincluded},2);
597 $totaltax += $form->{"tax_$i"};
598 map { $a[$j]->{$_} = $form->{"${_}_$i"} } @flds;
603 $form->redo_rows(\@flds, \@a, $count, $form->{rowcount});
604 $form->{rowcount} = $count + ($params{dont_add_new_row} ? 0 : 1);
605 map { $form->{invtotal} += $form->{"amount_$_"} } (1 .. $form->{rowcount});
607 $form->{forex} = $form->check_exchangerate( \%myconfig, $form->{currency}, $form->{transdate}, 'buy');
608 $form->{exchangerate} = $form->{forex} if $form->{forex};
610 $form->{invdate} = $form->{transdate};
612 if (($form->{previous_customer_id} || $form->{customer_id}) != $form->{customer_id}) {
613 IS->get_customer(\%myconfig, $form);
617 ($form->{taxincluded}) ? $form->{invtotal} : $form->{invtotal} + $totaltax;
619 for my $i (1 .. $form->{paidaccounts}) {
620 if ($form->parse_amount(\%myconfig, $form->{"paid_$i"})) {
623 $form->parse_amount(\%myconfig, $form->{"${_}_$i"})
624 } qw(paid exchangerate);
626 $form->{totalpaid} += $form->{"paid_$i"};
628 $form->{"forex_$i"} = $form->check_exchangerate( \%myconfig, $form->{currency}, $form->{"datepaid_$i"}, 'buy');
629 $form->{"exchangerate_$i"} = $form->{"forex_$i"} if $form->{"forex_$i"};
633 $form->{creditremaining} -=
634 ($form->{invtotal} - $form->{totalpaid} + $form->{oldtotalpaid} -
635 $form->{oldinvtotal});
636 $form->{oldinvtotal} = $form->{invtotal};
637 $form->{oldtotalpaid} = $form->{totalpaid};
641 $main::lxdebug->leave_sub();
645 # ToDO: fix $closedto and $invdate
648 $main::lxdebug->enter_sub();
650 $main::auth->assert('ar_transactions');
652 my $form = $main::form;
653 my %myconfig = %main::myconfig;
654 my $locale = $main::locale;
656 $form->mtime_ischanged('ar');
657 $form->{defaultcurrency} = $form->get_default_currency(\%myconfig);
659 my $invdate = $form->datetonum($form->{transdate}, \%myconfig);
661 for my $i (1 .. $form->{paidaccounts}) {
663 if ($form->parse_amount(\%myconfig, $form->{"paid_$i"})) {
664 my $datepaid = $form->datetonum($form->{"datepaid_$i"}, \%myconfig);
666 $form->isblank("datepaid_$i", $locale->text('Payment date missing!'));
668 $form->error($locale->text('Cannot post transaction above the maximum future booking date!'))
669 if ($form->date_max_future($form->{"datepaid_$i"}, \%myconfig));
671 #Zusätzlich noch das Buchungsdatum in die BĂ¼cherkontrolle einbeziehen
672 # (Dient zur PrĂ¼fung ob ZE oder ZA geprĂ¼ft werden soll)
673 $form->error($locale->text('Cannot post payment for a closed period!'))
674 if ($form->date_closed($form->{"datepaid_$i"}) && !$form->date_closed($form->{"gldate_$i"}, \%myconfig));
676 if ($form->{defaultcurrency} && ($form->{currency} ne $form->{defaultcurrency})) {
677 # $form->{"exchangerate_$i"} = $form->{exchangerate} if ($invdate == $datepaid);
678 $form->isblank("exchangerate_$i", $locale->text('Exchangerate for payment missing!'));
683 ($form->{AR}) = split /--/, $form->{AR};
684 ($form->{AR_paid}) = split /--/, $form->{AR_paid};
685 if (AR->post_payment(\%myconfig, \%$form)) {
686 $form->{snumbers} = qq|invnumber_| . $form->{invnumber};
687 $form->{what_done} = 'invoice';
688 $form->{addition} = "PAYMENT POSTED";
690 $form->redirect($locale->text('Payment posted!'))
692 $form->error($locale->text('Cannot post payment!'));
695 $main::lxdebug->leave_sub();
700 $main::auth->assert('ar_transactions');
702 my $form = $main::form;
709 $main::lxdebug->enter_sub();
711 $main::auth->assert('ar_transactions');
713 my $form = $main::form;
714 my %myconfig = %main::myconfig;
715 my $locale = $main::locale;
719 $form->mtime_ischanged('ar');
723 # check if there is an invoice number, invoice and due date
724 $form->isblank("transdate", $locale->text('Invoice Date missing!'));
725 $form->isblank("duedate", $locale->text('Due Date missing!'));
726 $form->isblank("customer_id", $locale->text('Customer missing!'));
728 if ($myconfig{mandatory_departments} && !$form->{department_id}) {
729 $form->{saved_message} = $::locale->text('You have to specify a department.');
734 my $closedto = $form->datetonum($form->{closedto}, \%myconfig);
735 my $transdate = $form->datetonum($form->{transdate}, \%myconfig);
737 $form->error($locale->text('Cannot post transaction above the maximum future booking date!'))
738 if ($form->date_max_future($transdate, \%myconfig));
740 $form->error($locale->text('Cannot post transaction for a closed period!')) if ($form->date_closed($form->{"transdate"}, \%myconfig));
742 $form->error($locale->text('Zero amount posting!'))
743 unless grep $_*1, map $form->parse_amount(\%myconfig, $form->{"amount_$_"}), 1..$form->{rowcount};
745 $form->isblank("exchangerate", $locale->text('Exchangerate missing!'))
746 if ($form->{defaultcurrency} && ($form->{currency} ne $form->{defaultcurrency}));
750 for my $i (1 .. $form->{paidaccounts}) {
751 if ($form->parse_amount(\%myconfig, $form->{"paid_$i"})) {
752 $datepaid = $form->datetonum($form->{"datepaid_$i"}, \%myconfig);
754 $form->isblank("datepaid_$i", $locale->text('Payment date missing!'));
756 $form->error($locale->text('Cannot post transaction above the maximum future booking date!'))
757 if ($form->date_max_future($form->{"datepaid_$i"}, \%myconfig));
759 #Zusätzlich noch das Buchungsdatum in die BĂ¼cherkontrolle einbeziehen
760 # (Dient zur PrĂ¼fung ob ZE oder ZA geprĂ¼ft werden soll)
761 $form->error($locale->text('Cannot post payment for a closed period!'))
762 if ($form->date_closed($form->{"datepaid_$i"}) && !$form->date_closed($form->{"gldate_$i"}, \%myconfig));
764 if ($form->{defaultcurrency} && ($form->{currency} ne $form->{defaultcurrency})) {
765 $form->{"exchangerate_$i"} = $form->{exchangerate} if ($transdate == $datepaid);
766 $form->isblank("exchangerate_$i", $locale->text('Exchangerate for payment missing!'));
771 # if oldcustomer ne customer redo form
772 if (($form->{previous_customer_id} || $form->{customer_id}) != $form->{customer_id}) {
774 $::dispatcher->end_request;
777 $form->{AR}{receivables} = $form->{ARselected};
780 $form->{id} = 0 if $form->{postasnew};
781 $form->error($locale->text('Cannot post transaction!')) unless AR->post_transaction(\%myconfig, \%$form);
784 if(!exists $form->{addition} && $form->{id} ne "") {
785 $form->{snumbers} = "invnumber_$form->{invnumber}";
786 $form->{what_done} = "invoice";
787 $form->{addition} = "POSTED";
790 # /saving the history
792 $form->redirect($locale->text("AR transaction posted.")) unless $inline;
794 $main::lxdebug->leave_sub();
798 $main::lxdebug->enter_sub();
800 $main::auth->assert('ar_transactions');
802 my $form = $main::form;
803 my %myconfig = %main::myconfig;
805 $form->{postasnew} = 1;
807 if(!exists $form->{addition} && $form->{id} ne "") {
808 $form->{snumbers} = qq|invnumber_| . $form->{invnumber};
809 $form->{what_done} = "invoice";
810 $form->{addition} = "POSTED AS NEW";
813 # /saving the history
816 $main::lxdebug->leave_sub();
820 $main::lxdebug->enter_sub();
822 $main::auth->assert('ar_transactions');
824 my $form = $main::form;
825 my %myconfig = %main::myconfig;
827 map { delete $form->{$_} } qw(printed emailed queued invnumber deliverydate id datepaid_1 gldate_1 acc_trans_id_1 source_1 memo_1 paid_1 exchangerate_1 AP_paid_1 storno);
828 $form->{paidaccounts} = 1;
831 my $today = DateTime->today_local;
832 $form->{transdate} = $today->to_kivitendo;
833 $form->{duedate} = $form->{transdate};
835 if ($form->{customer_id}) {
836 my $payment_terms = SL::DB::Customer->load_cached($form->{customer_id})->payment;
837 $form->{duedate} = $payment_terms->calc_date(reference_date => $today)->to_kivitendo if $payment_terms;
842 $main::lxdebug->leave_sub();
846 $::auth->assert('ar_transactions');
848 my $form = $main::form;
849 my %myconfig = %main::myconfig;
850 my $locale = $main::locale;
852 if (AR->delete_transaction(\%myconfig, \%$form)) {
854 if(!exists $form->{addition}) {
855 $form->{snumbers} = qq|invnumber_| . $form->{invnumber};
856 $form->{what_done} = "invoice";
857 $form->{addition} = "DELETED";
860 # /saving the history
861 $form->redirect($locale->text('Transaction deleted!'));
863 $form->error($locale->text('Cannot delete transaction!'));
866 sub setup_ar_search_action_bar {
869 for my $bar ($::request->layout->get('actionbar')) {
872 $::locale->text('Search'),
873 submit => [ '#form' ],
874 accesskey => 'enter',
880 sub setup_ar_transactions_action_bar {
883 for my $bar ($::request->layout->get('actionbar')) {
886 $::locale->text('Print'),
887 call => [ 'kivi.MassInvoiceCreatePrint.showMassPrintOptionsOrDownloadDirectly' ],
888 disabled => !$params{num_rows} ? $::locale->text('The report doesn\'t contain entries.') : undef,
892 action => [ $::locale->text('Create new') ],
894 $::locale->text('AR Transaction'),
895 submit => [ '#create_new_form', { action => 'ar_transaction' } ],
898 $::locale->text('Sales Invoice'),
899 submit => [ '#create_new_form', { action => 'sales_invoice' } ],
901 ], # end of combobox "Create new"
907 $main::lxdebug->enter_sub();
909 $main::auth->assert('invoice_edit');
911 my $form = $main::form;
912 my %myconfig = %main::myconfig;
913 my $locale = $main::locale;
914 my $cgi = $::request->{cgi};
916 $form->{title} = $locale->text('AR Transactions');
918 $form->{ALL_EMPLOYEES} = SL::DB::Manager::Employee->get_all_sorted(query => [ deleted => 0 ]);
919 $form->{ALL_DEPARTMENTS} = SL::DB::Manager::Department->get_all_sorted;
920 $form->{ALL_BUSINESS_TYPES} = SL::DB::Manager::Business->get_all_sorted;
922 $form->{CT_CUSTOM_VARIABLES} = CVar->get_configs('module' => 'CT');
923 ($form->{CT_CUSTOM_VARIABLES_FILTER_CODE},
924 $form->{CT_CUSTOM_VARIABLES_INCLUSION_CODE}) = CVar->render_search_options('variables' => $form->{CT_CUSTOM_VARIABLES},
925 'include_prefix' => 'l_',
926 'include_value' => 'Y');
928 # constants and subs for template
929 $form->{vc_keys} = sub { "$_[0]->{name}--$_[0]->{id}" };
931 $::request->layout->add_javascripts("autocomplete_project.js");
933 setup_ar_search_action_bar();
936 print $form->parse_html_template('ar/search', { %myconfig });
938 $main::lxdebug->leave_sub();
941 sub create_subtotal_row {
942 $main::lxdebug->enter_sub();
944 my ($totals, $columns, $column_alignment, $subtotal_columns, $class) = @_;
946 my $form = $main::form;
947 my %myconfig = %main::myconfig;
949 my $row = { map { $_ => { 'data' => '', 'class' => $class, 'align' => $column_alignment->{$_}, } } @{ $columns } };
951 map { $row->{$_}->{data} = $form->format_amount(\%myconfig, $totals->{$_}, 2) } @{ $subtotal_columns };
953 $row->{tax}->{data} = $form->format_amount(\%myconfig, $totals->{amount} - $totals->{netamount}, 2);
955 map { $totals->{$_} = 0 } @{ $subtotal_columns };
957 $main::lxdebug->leave_sub();
962 sub ar_transactions {
963 $main::lxdebug->enter_sub();
965 $main::auth->assert('invoice_edit');
967 my $form = $main::form;
968 my %myconfig = %main::myconfig;
969 my $locale = $main::locale;
971 my ($callback, $href, @columns);
973 report_generator_set_default_sort('transdate', 1);
975 AR->ar_transactions(\%myconfig, \%$form);
977 $form->{title} = $locale->text('AR Transactions');
979 my $report = SL::ReportGenerator->new(\%myconfig, $form);
982 qw(ids transdate id type invnumber ordnumber cusordnumber name netamount tax amount paid
983 datepaid due duedate transaction_description notes salesman employee shippingpoint shipvia
984 marge_total marge_percent globalprojectnumber customernumber country ustid taxzone
985 payment_terms charts customertype direct_debit dunning_description department);
987 my $ct_cvar_configs = CVar->get_configs('module' => 'CT');
988 my @ct_includeable_custom_variables = grep { $_->{includeable} } @{ $ct_cvar_configs };
989 my @ct_searchable_custom_variables = grep { $_->{searchable} } @{ $ct_cvar_configs };
991 my %column_defs_cvars = map { +"cvar_$_->{name}" => { 'text' => $_->{description} } } @ct_includeable_custom_variables;
992 push @columns, map { "cvar_$_->{name}" } @ct_includeable_custom_variables;
994 my @hidden_variables = map { "l_${_}" } @columns;
995 push @hidden_variables, "l_subtotal", qw(open closed customer invnumber ordnumber cusordnumber transaction_description notes project_id transdatefrom transdateto duedatefrom duedateto
996 employee_id salesman_id business_id parts_partnumber parts_description department_id);
997 push @hidden_variables, map { "cvar_$_->{name}" } @ct_searchable_custom_variables;
999 $href = build_std_url('action=ar_transactions', grep { $form->{$_} } @hidden_variables);
1002 'ids' => { raw_header_data => $::request->presenter->checkbox_tag("", id => "check_all", checkall => "[data-checkall=1]"), align => 'center' },
1003 'transdate' => { 'text' => $locale->text('Date'), },
1004 'id' => { 'text' => $locale->text('ID'), },
1005 'type' => { 'text' => $locale->text('Type'), },
1006 'invnumber' => { 'text' => $locale->text('Invoice'), },
1007 'ordnumber' => { 'text' => $locale->text('Order'), },
1008 'cusordnumber' => { 'text' => $locale->text('Customer Order Number'), },
1009 'name' => { 'text' => $locale->text('Customer'), },
1010 'netamount' => { 'text' => $locale->text('Amount'), },
1011 'tax' => { 'text' => $locale->text('Tax'), },
1012 'amount' => { 'text' => $locale->text('Total'), },
1013 'paid' => { 'text' => $locale->text('Paid'), },
1014 'datepaid' => { 'text' => $locale->text('Date Paid'), },
1015 'due' => { 'text' => $locale->text('Amount Due'), },
1016 'duedate' => { 'text' => $locale->text('Due Date'), },
1017 'transaction_description' => { 'text' => $locale->text('Transaction description'), },
1018 'notes' => { 'text' => $locale->text('Notes'), },
1019 'salesman' => { 'text' => $locale->text('Salesperson'), },
1020 'employee' => { 'text' => $locale->text('Employee'), },
1021 'shippingpoint' => { 'text' => $locale->text('Shipping Point'), },
1022 'shipvia' => { 'text' => $locale->text('Ship via'), },
1023 'globalprojectnumber' => { 'text' => $locale->text('Document Project Number'), },
1024 'marge_total' => { 'text' => $locale->text('Ertrag'), },
1025 'marge_percent' => { 'text' => $locale->text('Ertrag prozentual'), },
1026 'customernumber' => { 'text' => $locale->text('Customer Number'), },
1027 'country' => { 'text' => $locale->text('Country'), },
1028 'ustid' => { 'text' => $locale->text('USt-IdNr.'), },
1029 'taxzone' => { 'text' => $locale->text('Steuersatz'), },
1030 'payment_terms' => { 'text' => $locale->text('Payment Terms'), },
1031 'charts' => { 'text' => $locale->text('Buchungskonto'), },
1032 'customertype' => { 'text' => $locale->text('Customer type'), },
1033 'direct_debit' => { 'text' => $locale->text('direct debit'), },
1034 'department' => { 'text' => $locale->text('Department'), },
1035 dunning_description => { 'text' => $locale->text('Dunning level'), },
1039 foreach my $name (qw(id transdate duedate invnumber ordnumber cusordnumber name datepaid employee shippingpoint shipvia transaction_description direct_debit)) {
1040 my $sortdir = $form->{sort} eq $name ? 1 - $form->{sortdir} : $form->{sortdir};
1041 $column_defs{$name}->{link} = $href . "&sort=$name&sortdir=$sortdir";
1044 my %column_alignment = map { $_ => 'right' } qw(netamount tax amount paid due);
1046 $form->{"l_type"} = "Y";
1047 map { $column_defs{$_}->{visible} = $form->{"l_${_}"} ? 1 : 0 } @columns;
1049 $column_defs{ids}->{visible} = 'HTML';
1051 $report->set_columns(%column_defs);
1052 $report->set_column_order(@columns);
1054 $report->set_export_options('ar_transactions', @hidden_variables, qw(sort sortdir));
1056 $report->set_sort_indicator($form->{sort}, $form->{sortdir});
1058 CVar->add_custom_variables_to_report('module' => 'CT',
1059 'trans_id_field' => 'customer_id',
1060 'configs' => $ct_cvar_configs,
1061 'column_defs' => \%column_defs,
1062 'data' => $form->{AR});
1065 if ($form->{customer}) {
1066 push @options, $locale->text('Customer') . " : $form->{customer}";
1068 if ($form->{cp_name}) {
1069 push @options, $locale->text('Contact Person') . " : $form->{cp_name}";
1072 if ($form->{department_id}) {
1073 my $department = SL::DB::Manager::Department->find_by( id => $form->{department_id} );
1074 push @options, $locale->text('Department') . " : " . $department->description;
1076 if ($form->{invnumber}) {
1077 push @options, $locale->text('Invoice Number') . " : $form->{invnumber}";
1079 if ($form->{ordnumber}) {
1080 push @options, $locale->text('Order Number') . " : $form->{ordnumber}";
1082 if ($form->{cusordnumber}) {
1083 push @options, $locale->text('Customer Order Number') . " : $form->{cusordnumber}";
1085 if ($form->{notes}) {
1086 push @options, $locale->text('Notes') . " : $form->{notes}";
1088 if ($form->{transaction_description}) {
1089 push @options, $locale->text('Transaction description') . " : $form->{transaction_description}";
1091 if ($form->{parts_partnumber}) {
1092 push @options, $locale->text('Part Number') . " : $form->{parts_partnumber}";
1094 if ($form->{parts_description}) {
1095 push @options, $locale->text('Part Description') . " : $form->{parts_description}";
1097 if ($form->{transdatefrom}) {
1098 push @options, $locale->text('From') . " " . $locale->date(\%myconfig, $form->{transdatefrom}, 1);
1100 if ($form->{transdateto}) {
1101 push @options, $locale->text('Bis') . " " . $locale->date(\%myconfig, $form->{transdateto}, 1);
1103 if ($form->{open}) {
1104 push @options, $locale->text('Open');
1106 if ($form->{employee_id}) {
1107 my $employee = SL::DB::Employee->new(id => $form->{employee_id})->load;
1108 push @options, $locale->text('Employee') . ' : ' . $employee->name;
1110 if ($form->{salesman_id}) {
1111 my $salesman = SL::DB::Employee->new(id => $form->{salesman_id})->load;
1112 push @options, $locale->text('Salesman') . ' : ' . $salesman->name;
1114 if ($form->{closed}) {
1115 push @options, $locale->text('Closed');
1118 $form->{ALL_PRINTERS} = SL::DB::Manager::Printer->get_all_sorted;
1120 $report->set_options('top_info_text' => join("\n", @options),
1121 'raw_top_info_text' => $form->parse_html_template('ar/ar_transactions_header'),
1122 'raw_bottom_info_text' => $form->parse_html_template('ar/ar_transactions_bottom'),
1123 'output_format' => 'HTML',
1124 'title' => $form->{title},
1125 'attachment_basename' => $locale->text('invoice_list') . strftime('_%Y%m%d', localtime time),
1127 $report->set_options_from_form();
1128 $locale->set_numberformat_wo_thousands_separator(\%myconfig) if lc($report->{options}->{output_format}) eq 'csv';
1130 # add sort and escape callback, this one we use for the add sub
1131 $form->{callback} = $href .= "&sort=$form->{sort}";
1133 # escape callback for href
1134 $callback = $form->escape($href);
1136 my @subtotal_columns = qw(netamount amount paid due marge_total marge_percent);
1138 my %totals = map { $_ => 0 } @subtotal_columns;
1139 my %subtotals = map { $_ => 0 } @subtotal_columns;
1143 foreach my $ar (@{ $form->{AR} }) {
1144 $ar->{tax} = $ar->{amount} - $ar->{netamount};
1145 $ar->{due} = $ar->{amount} - $ar->{paid};
1147 map { $subtotals{$_} += $ar->{$_};
1148 $totals{$_} += $ar->{$_} } @subtotal_columns;
1150 $subtotals{marge_percent} = $subtotals{netamount} ? ($subtotals{marge_total} * 100 / $subtotals{netamount}) : 0;
1151 $totals{marge_percent} = $totals{netamount} ? ($totals{marge_total} * 100 / $totals{netamount} ) : 0;
1153 my $is_storno = $ar->{storno} && $ar->{storno_id};
1154 my $has_storno = $ar->{storno} && !$ar->{storno_id};
1157 $has_storno ? $locale->text("Invoice with Storno (abbreviation)") :
1158 $is_storno ? $locale->text("Storno (one letter abbreviation)") :
1159 $ar->{amount} < 0 ? $locale->text("Credit note (one letter abbreviation)") :
1160 $ar->{invoice} ? $locale->text("Invoice (one letter abbreviation)") :
1161 $locale->text("AR Transaction (abbreviation)");
1163 map { $ar->{$_} = $form->format_amount(\%myconfig, $ar->{$_}, 2) } qw(netamount tax amount paid due marge_total marge_percent);
1165 $ar->{direct_debit} = $ar->{direct_debit} ? $::locale->text('yes') : $::locale->text('no');
1169 foreach my $column (@columns) {
1171 'data' => $ar->{$column},
1172 'align' => $column_alignment{$column},
1176 $row->{invnumber}->{link} = build_std_url("script=" . ($ar->{invoice} ? 'is.pl' : 'ar.pl'), 'action=edit')
1177 . "&id=" . E($ar->{id}) . "&callback=${callback}";
1180 raw_data => $::request->presenter->checkbox_tag("id[]", value => $ar->{id}, "data-checkall" => 1),
1185 my $row_set = [ $row ];
1187 if (($form->{l_subtotal} eq 'Y')
1188 && (($idx == (scalar @{ $form->{AR} } - 1))
1189 || ($ar->{ $form->{sort} } ne $form->{AR}->[$idx + 1]->{ $form->{sort} }))) {
1190 push @{ $row_set }, create_subtotal_row(\%subtotals, \@columns, \%column_alignment, \@subtotal_columns, 'listsubtotal');
1193 $report->add_data($row_set);
1198 $report->add_separator();
1199 $report->add_data(create_subtotal_row(\%totals, \@columns, \%column_alignment, \@subtotal_columns, 'listtotal'));
1201 $::request->layout->add_javascripts('kivi.MassInvoiceCreatePrint.js');
1202 setup_ar_transactions_action_bar(num_rows => scalar(@{ $form->{AR} }));
1204 $report->generate_with_headers();
1206 $main::lxdebug->leave_sub();
1210 $main::lxdebug->enter_sub();
1212 $main::auth->assert('ar_transactions');
1214 my $form = $main::form;
1215 my %myconfig = %main::myconfig;
1216 my $locale = $main::locale;
1218 # don't cancel cancelled transactions
1219 if (IS->has_storno(\%myconfig, $form, 'ar')) {
1220 $form->{title} = $locale->text("Cancel Accounts Receivables Transaction");
1221 $form->error($locale->text("Transaction has already been cancelled!"));
1224 AR->storno($form, \%myconfig, $form->{id});
1226 # saving the history
1227 if(!exists $form->{addition} && $form->{id} ne "") {
1228 $form->{snumbers} = qq|invnumber_| . $form->{invnumber};
1229 $form->{addition} = "STORNO";
1230 $form->{what_done} = "invoice";
1231 $form->save_history;
1233 # /saving the history
1235 $form->redirect(sprintf $locale->text("Transaction %d cancelled."), $form->{storno_id});
1237 $main::lxdebug->leave_sub();
1240 sub setup_ar_form_header_action_bar {
1241 my $transdate = $::form->datetonum($::form->{transdate}, \%::myconfig);
1242 my $closedto = $::form->datetonum($::form->{closedto}, \%::myconfig);
1243 my $is_closed = $transdate <= $closedto;
1245 my $change_never = $::instance_conf->get_ar_changeable == 0;
1246 my $change_on_same_day_only = $::instance_conf->get_ar_changeable == 2 && ($::form->current_date(\%::myconfig) ne $::form->{gldate});
1248 my $is_storno = IS->is_storno(\%::myconfig, $::form, 'ar', $::form->{id});
1249 my $has_storno = IS->has_storno(\%::myconfig, $::form, 'ar');
1251 for my $bar ($::request->layout->get('actionbar')) {
1255 submit => [ '#form', { action => "update" } ],
1256 id => 'update_button',
1257 accesskey => 'enter',
1263 submit => [ '#form', { action => "post" } ],
1264 checks => [ 'kivi.AR.check_fields_before_posting' ],
1265 disabled => $is_closed ? t8('The billing period has already been locked.')
1266 : $is_storno ? t8('A canceled invoice cannot be posted.')
1267 : ($::form->{id} && $change_never) ? t8('Changing invoices has been disabled in the configuration.')
1268 : ($::form->{id} && $change_on_same_day_only) ? t8('Invoices can only be changed on the day they are posted.')
1273 submit => [ '#form', { action => "post_payment" } ],
1274 disabled => !$::form->{id} ? t8('This invoice has not been posted yet.') : undef,
1276 action => [ t8('Mark as paid'),
1277 submit => [ '#form', { action => "mark_as_paid" } ],
1278 confirm => t8('This will remove the invoice from showing as unpaid even if the unpaid amount does not match the amount. Proceed?'),
1279 disabled => !$::form->{id} ? t8('This invoice has not been posted yet.') : undef,
1280 only_if => $::instance_conf->get_is_show_mark_as_paid,
1282 ], # end of combobox "Post"
1285 action => [ t8('Storno'),
1286 submit => [ '#form', { action => "storno" } ],
1287 checks => [ 'kivi.AR.check_fields_before_posting' ],
1288 confirm => t8('Do you really want to cancel this invoice?'),
1289 disabled => !$::form->{id} ? t8('This invoice has not been posted yet.')
1290 : $has_storno ? t8('This invoice has been canceled already.')
1291 : $is_storno ? t8('Reversal invoices cannot be canceled.')
1292 : $::form->{totalpaid} ? t8('Invoices with payments cannot be canceled.')
1295 action => [ t8('Delete'),
1296 submit => [ '#form', { action => "delete" } ],
1297 confirm => t8('Do you really want to delete this object?'),
1298 disabled => !$::form->{id} ? t8('This invoice has not been posted yet.')
1299 : $change_never ? t8('Changing invoices has been disabled in the configuration.')
1300 : $change_on_same_day_only ? t8('Invoices can only be changed on the day they are posted.')
1301 : $is_closed ? t8('The billing period has already been locked.')
1304 ], # end of combobox "Storno"
1309 action => [ t8('Workflow') ],
1312 submit => [ '#form', { action => "use_as_new" } ],
1313 disabled => !$::form->{id} ? t8('This invoice has not been posted yet.') : undef,
1315 ], # end of combobox "Workflow"
1318 action => [ t8('more') ],
1321 call => [ 'set_history_window', $::form->{id} * 1, 'glid' ],
1322 disabled => !$::form->{id} ? t8('This invoice has not been posted yet.') : undef,
1326 call => [ 'follow_up_window' ],
1327 disabled => !$::form->{id} ? t8('This invoice has not been posted yet.') : undef,
1330 t8('Record templates'),
1331 call => [ 'kivi.RecordTemplate.popup', 'ar_transaction' ],
1335 call => [ 'kivi.Draft.popup', 'ar', 'invoice', $::form->{draft_id}, $::form->{draft_description} ],
1336 disabled => $::form->{id} ? t8('This invoice has already been posted.')
1337 : $is_closed ? t8('The billing period has already been locked.')
1340 ], # end of combobox "more"