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;
44 use SL::DB::BankTransactionAccTrans;
51 use SL::DB::RecordTemplate;
53 use SL::Helper::Flash qw(flash);
54 use SL::Locale::String qw(t8);
55 use SL::Presenter::Tag;
56 use SL::Presenter::Chart;
57 use SL::ReportGenerator;
59 require "bin/mozilla/common.pl";
60 require "bin/mozilla/reportgenerator.pl";
65 # this is for our long dates
66 # $locale->text('January')
67 # $locale->text('February')
68 # $locale->text('March')
69 # $locale->text('April')
70 # $locale->text('May ')
71 # $locale->text('June')
72 # $locale->text('July')
73 # $locale->text('August')
74 # $locale->text('September')
75 # $locale->text('October')
76 # $locale->text('November')
77 # $locale->text('December')
79 # this is for our short month
80 # $locale->text('Jan')
81 # $locale->text('Feb')
82 # $locale->text('Mar')
83 # $locale->text('Apr')
84 # $locale->text('May')
85 # $locale->text('Jun')
86 # $locale->text('Jul')
87 # $locale->text('Aug')
88 # $locale->text('Sep')
89 # $locale->text('Oct')
90 # $locale->text('Nov')
91 # $locale->text('Dec')
93 sub _may_view_or_edit_this_invoice {
94 return 1 if $::auth->assert('ar_transactions', 1); # may edit all invoices
95 return 0 if !$::form->{id}; # creating new invoices isn't allowed without invoice_edit
96 return 0 if !$::form->{globalproject_id}; # existing records without a project ID are not allowed
97 return SL::DB::Project->new(id => $::form->{globalproject_id})->load->may_employee_view_project_invoices(SL::DB::Manager::Employee->current);
101 my $cache = $::request->cache('ar.pl::_assert_access');
103 $cache->{_may_view_or_edit_this_invoice} = _may_view_or_edit_this_invoice() if !exists $cache->{_may_view_or_edit_this_invoice};
104 $::form->show_generic_error($::locale->text("You do not have the permissions to access this function.")) if ! $cache->{_may_view_or_edit_this_invoice};
107 sub load_record_template {
108 $::auth->assert('ar_transactions');
110 # Load existing template and verify that its one for this module.
111 my $template = SL::DB::RecordTemplate
112 ->new(id => $::form->{id})
114 with_object => [ qw(customer payment currency record_items record_items.chart) ],
117 die "invalid template type" unless $template->template_type eq 'ar_transaction';
119 $template->substitute_variables;
121 # Clean the current $::form before rebuilding it from the template.
122 my $form_defaults = delete $::form->{form_defaults};
123 delete @{ $::form }{ grep { !m{^(?:script|login)$}i } keys %{ $::form } };
125 # Fill $::form from the template.
126 my $today = DateTime->today_local;
127 $::form->{title} = "Add";
128 $::form->{currency} = $template->currency->name;
129 $::form->{direct_debit} = $template->direct_debit;
130 $::form->{globalproject_id} = $template->project_id;
131 $::form->{AR_chart_id} = $template->ar_ap_chart_id;
132 $::form->{transdate} = $today->to_kivitendo;
133 $::form->{duedate} = $today->to_kivitendo;
134 $::form->{rowcount} = @{ $template->items };
135 $::form->{paidaccounts} = 1;
136 $::form->{$_} = $template->$_ for qw(department_id ordnumber taxincluded employee_id notes);
138 if ($template->customer) {
139 $::form->{customer_id} = $template->customer_id;
140 $::form->{customer} = $template->customer->name;
141 $::form->{duedate} = $template->customer->payment->calc_date(reference_date => $today)->to_kivitendo if $template->customer->payment;
145 foreach my $item (@{ $template->items }) {
148 my $active_taxkey = $item->chart->get_active_taxkey;
149 my $taxes = SL::DB::Manager::Tax->get_all(
150 where => [ chart_categories => { like => '%' . $item->chart->category . '%' }],
151 sort_by => 'taxkey, rate',
154 my $tax = first { $item->tax_id == $_->id } @{ $taxes };
155 $tax //= first { $active_taxkey->tax_id == $_->id } @{ $taxes };
156 $tax //= $taxes->[0];
163 $::form->{"AR_amount_chart_id_${row}"} = $item->chart_id;
164 $::form->{"previous_AR_amount_chart_id_${row}"} = $item->chart_id;
165 $::form->{"amount_${row}"} = $::form->format_amount(\%::myconfig, $item->amount1, 2);
166 $::form->{"taxchart_${row}"} = $item->tax_id . '--' . $tax->rate;
167 $::form->{"project_id_${row}"} = $item->project_id;
170 $::form->{$_} = $form_defaults->{$_} for keys %{ $form_defaults // {} };
172 flash('info', $::locale->text("The record template '#1' has been loaded.", $template->template_name));
175 keep_rows_without_amount => 1,
176 dont_add_new_row => 1,
180 sub save_record_template {
181 $::auth->assert('ar_transactions');
183 my $template = $::form->{record_template_id} ? SL::DB::RecordTemplate->new(id => $::form->{record_template_id})->load : SL::DB::RecordTemplate->new;
184 my $js = SL::ClientJS->new(controller => SL::Controller::Base->new);
185 my $new_name = $template->template_name_to_use($::form->{record_template_new_template_name});
187 $js->dialog->close('#record_template_dialog');
190 $_->{chart_id} && (($_->{tax_id} // '') ne '')
192 +{ chart_id => $::form->{"AR_amount_chart_id_${_}"},
193 amount1 => $::form->parse_amount(\%::myconfig, $::form->{"amount_${_}"}),
194 tax_id => (split m{--}, $::form->{"taxchart_${_}"})[0],
195 project_id => $::form->{"project_id_${_}"} || undef,
197 } (1..($::form->{rowcount} || 1));
199 $template->assign_attributes(
200 template_type => 'ar_transaction',
201 template_name => $new_name,
203 currency_id => SL::DB::Manager::Currency->find_by(name => $::form->{currency})->id,
204 ar_ap_chart_id => $::form->{AR_chart_id} || undef,
205 customer_id => $::form->{customer_id} || undef,
206 department_id => $::form->{department_id} || undef,
207 project_id => $::form->{globalproject_id} || undef,
208 employee_id => $::form->{employee_id} || undef,
209 taxincluded => $::form->{taxincluded} ? 1 : 0,
210 direct_debit => $::form->{direct_debit} ? 1 : 0,
211 ordnumber => $::form->{ordnumber},
212 notes => $::form->{notes},
222 ->flash('error', $::locale->text("Saving the record template '#1' failed.", $new_name))
227 ->flash('info', $::locale->text("The record template '#1' has been saved.", $new_name))
232 $main::lxdebug->enter_sub();
234 $main::auth->assert('ar_transactions');
236 my $form = $main::form;
237 my %myconfig = %main::myconfig;
240 if(!exists $form->{addition} && ($form->{id} ne "")) {
241 $form->{snumbers} = qq|invnumber_| . $form->{invnumber};
242 $form->{addition} = "ADDED";
245 # /saving the history
247 $form->{title} = "Add";
248 $form->{callback} = "ar.pl?action=add" unless $form->{callback};
250 AR->get_transdate(\%myconfig, $form);
251 $form->{initial_transdate} = $form->{transdate};
252 create_links(dont_save => 1);
253 $form->{transdate} = $form->{initial_transdate};
255 if ($form->{customer_id}) {
256 my $last_used_ar_chart = SL::DB::Customer->load_cached($form->{customer_id})->last_used_ar_chart;
257 $form->{"AR_amount_chart_id_1"} = $last_used_ar_chart->id if $last_used_ar_chart;
261 $main::lxdebug->leave_sub();
265 $main::lxdebug->enter_sub();
267 # Delay access check to after the invoice's been loaded in
268 # "create_links" so that project-specific invoice rights can be
271 my $form = $main::form;
273 # show history button
274 $form->{javascript} = qq|<script type="text/javascript" src="js/show_history.js"></script>|;
275 #/show hhistory button
276 $form->{javascript} .= qq|<script type="text/javascript" src="js/common.js"></script>|;
277 $form->{title} = "Edit";
282 $main::lxdebug->leave_sub();
286 $main::lxdebug->enter_sub();
290 my $form = $main::form;
295 $main::lxdebug->leave_sub();
298 sub _retrieve_invoice_object {
299 return undef if !$::form->{id};
300 return $::form->{invoice_obj} if $::form->{invoice_obj} && $::form->{invoice_obj}->id == $::form->{id};
301 return SL::DB::Invoice->new(id => $::form->{id})->load;
305 $main::lxdebug->enter_sub();
307 # Delay access check to after the invoice's been loaded so that
308 # project-specific invoice rights can be evaluated.
311 my $form = $main::form;
312 my %myconfig = %main::myconfig;
314 $form->create_links("AR", \%myconfig, "customer");
315 $form->{invoice_obj} = _retrieve_invoice_object();
320 if (!$params{dont_save}) {
321 %saved = map { ($_ => $form->{$_}) } qw(direct_debit id taxincluded);
322 $saved{duedate} = $form->{duedate} if $form->{duedate};
323 $saved{currency} = $form->{currency} if $form->{currency};
326 IS->get_customer(\%myconfig, \%$form);
328 $form->{$_} = $saved{$_} for keys %saved;
329 $form->{rowcount} = 1;
330 $form->{AR_chart_id} = $form->{acc_trans} && $form->{acc_trans}->{AR} ? $form->{acc_trans}->{AR}->[0]->{chart_id} : $::instance_conf->get_ar_chart_id || $form->{AR_links}->{AR}->[0]->{chart_id};
333 $form->{defaultcurrency} = $form->get_default_currency(\%myconfig);
335 $form->{ALL_DEPARTMENTS} = SL::DB::Manager::Department->get_all_sorted;
337 # build the popup menus
338 $form->{taxincluded} = ($form->{id}) ? $form->{taxincluded} : "checked";
340 AR->setup_form($form);
343 ($form->datetonum($form->{transdate}, \%myconfig) <=
344 $form->datetonum($form->{closedto}, \%myconfig));
346 $main::lxdebug->leave_sub();
350 $main::lxdebug->enter_sub();
354 my $form = $main::form;
355 my %myconfig = %main::myconfig;
356 my $locale = $main::locale;
357 my $cgi = $::request->{cgi};
359 $form->{invoice_obj} = _retrieve_invoice_object();
361 my ($title, $readonly, $exchangerate, $rows);
362 my ($notes, $amount, $project);
364 $form->{initial_focus} = !($form->{amount_1} * 1) ? 'customer_id' : 'row_' . $form->{rowcount};
366 $title = $form->{title};
367 # $locale->text('Add Accounts Receivables Transaction')
368 # $locale->text('Edit Accounts Receivables Transaction')
369 $form->{title} = $locale->text("$title Accounts Receivables Transaction");
371 $readonly = ($form->{id}) ? "readonly" : "";
373 $form->{radier} = ($::instance_conf->get_ar_changeable == 2)
374 ? ($form->current_date(\%myconfig) eq $form->{gldate})
375 : ($::instance_conf->get_ar_changeable == 1);
376 $readonly = ($form->{radier}) ? "" : $readonly;
378 $form->{forex} = $form->check_exchangerate( \%myconfig, $form->{currency}, $form->{transdate}, 'buy');
379 $form->{exchangerate} = $form->{forex} if $form->{forex};
381 $rows = max 2, $form->numtextrows($form->{notes}, 50);
383 my @old_project_ids = grep { $_ } map { $form->{"project_id_$_"} } 1..$form->{rowcount};
385 $form->get_lists("projects" => { "key" => "ALL_PROJECTS",
387 "old_id" => \@old_project_ids },
388 "charts" => { "key" => "ALL_CHARTS",
389 "transdate" => $form->{transdate} },
390 "taxcharts" => { "key" => "ALL_TAXCHARTS",
391 "module" => "AR" },);
393 $form->{ALL_DEPARTMENTS} = SL::DB::Manager::Department->get_all_sorted;
395 $_->{link_split} = { map { $_ => 1 } split/:/, $_->{link} } for @{ $form->{ALL_CHARTS} };
397 my %project_labels = map { $_->{id} => $_->{projectnumber} } @{ $form->{"ALL_PROJECTS"} };
399 my (@AR_paid_values, %AR_paid_labels);
400 my $default_ar_amount_chart_id;
402 foreach my $item (@{ $form->{ALL_CHARTS} }) {
403 if ($item->{link_split}{AR_amount}) {
404 $default_ar_amount_chart_id //= $item->{id};
406 } elsif ($item->{link_split}{AR_paid}) {
407 push(@AR_paid_values, $item->{accno});
408 $AR_paid_labels{$item->{accno}} = "$item->{accno}--$item->{description}";
412 my $follow_up_vc = $form->{customer_id} ? SL::DB::Customer->load_cached($form->{customer_id})->name : '';
413 my $follow_up_trans_info = "$form->{invnumber} ($follow_up_vc)";
415 $::request->layout->add_javascripts("autocomplete_chart.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", "kivi.CustomerVendor.js", "kivi.Validator.js");
417 my $transdate = $::form->{transdate} ? DateTime->from_kivitendo($::form->{transdate}) : DateTime->today_local;
421 for my $i (1 .. $form->{rowcount}) {
423 amount => $form->{"amount_$i"},
424 tax => $form->{"tax_$i"},
425 project_id => ($i==$form->{rowcount}) ? $form->{globalproject_id} : $form->{"project_id_$i"},
428 my (%taxchart_labels, @taxchart_values, $default_taxchart, $taxchart_to_use);
429 my $amount_chart_id = $form->{"AR_amount_chart_id_$i"} // $default_ar_amount_chart_id;
432 if ( $form->{"taxchart_$i"} ) {
433 ($used_tax_id) = split(/--/, $form->{"taxchart_$i"});
435 foreach my $item ( GL->get_active_taxes_for_chart($amount_chart_id, $transdate, $used_tax_id) ) {
436 my $key = $item->id . "--" . $item->rate;
437 $first_taxchart //= $item;
438 $default_taxchart = $item if $item->{is_default};
439 $taxchart_to_use = $item if $key eq $form->{"taxchart_$i"};
441 push(@taxchart_values, $key);
442 $taxchart_labels{$key} = $item->taxkey . " - " . $item->taxdescription . " " . $item->rate * 100 . ' %';
445 $taxchart_to_use //= $default_taxchart // $first_taxchart;
446 my $selected_taxchart = $taxchart_to_use->id . '--' . $taxchart_to_use->rate;
448 $transaction->{selectAR_amount} =
449 SL::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" : ""))
450 . SL::Presenter::Tag::hidden_tag("previous_AR_amount_chart_id_$i", $amount_chart_id);
452 $transaction->{taxchart} =
453 NTI($cgi->popup_menu('-name' => "taxchart_$i",
454 '-id' => "taxchart_$i",
455 '-style' => 'width:200px',
456 '-values' => \@taxchart_values,
457 '-labels' => \%taxchart_labels,
458 '-default' => $selected_taxchart));
460 push @transactions, $transaction;
463 $form->{invtotal_unformatted} = $form->{invtotal};
465 $form->{paidaccounts}++ if ($form->{"paid_$form->{paidaccounts}"});
467 my $now = $form->current_date(\%myconfig);
470 for my $i (1 .. $form->{paidaccounts}) {
472 paid => $form->{"paid_$i"},
473 exchangerate => $form->{"exchangerate_$i"} || '',
474 gldate => $form->{"gldate_$i"},
475 acc_trans_id => $form->{"acc_trans_id_$i"},
476 source => $form->{"source_$i"},
477 memo => $form->{"memo_$i"},
478 AR_paid => $form->{"AR_paid_$i"},
479 forex => $form->{"forex_$i"},
480 datepaid => $form->{"datepaid_$i"},
481 paid_project_id => $form->{"paid_project_id_$i"},
482 gldate => $form->{"gldate_$i"},
485 # default account for current assets (i.e. 1801 - SKR04) if no account is selected
486 $form->{accno_arap} = IS->get_standard_accno_current_assets(\%myconfig, \%$form);
488 $payment->{selectAR_paid} =
489 NTI($cgi->popup_menu('-name' => "AR_paid_$i",
490 '-id' => "AR_paid_$i",
491 '-values' => \@AR_paid_values,
492 '-labels' => \%AR_paid_labels,
493 '-default' => $payment->{AR_paid} || $form->{accno_arap}));
497 $payment->{changeable} =
498 SL::DB::Default->get->payments_changeable == 0 ? !$payment->{acc_trans_id} # never
499 : SL::DB::Default->get->payments_changeable == 2 ? $payment->{gldate} eq '' || $payment->{gldate} eq $now
502 #deaktivieren von gebuchten Zahlungen ausserhalb der Bücherkontrolle, vorher prüfen ob heute eingegeben
503 if ($form->date_closed($payment->{"gldate_$i"})) {
504 $payment->{changeable} = 0;
507 push @payments, $payment;
510 my @empty = grep { $_->{paid} eq '' } @payments;
512 (sort_by { DateTime->from_kivitendo($_->{datepaid}) } grep { $_->{paid} ne '' } @payments),
516 $form->{totalpaid} = sum map { $_->{paid} } @payments;
518 my $employees = SL::DB::Manager::Employee->get_all_sorted(
521 (id => $::form->{employee_id}) x !!$::form->{employee_id},
528 setup_ar_form_header_action_bar();
531 print $::form->parse_html_template('ar/form_header', {
532 paid_missing => $::form->{invtotal} - $::form->{totalpaid},
533 show_exch => ($::form->{defaultcurrency} && ($::form->{currency} ne $::form->{defaultcurrency})),
534 payments => \@payments,
535 transactions => \@transactions,
536 project_labels => \%project_labels,
538 AR_chart_id => $form->{AR_chart_id},
540 follow_up_trans_info => $follow_up_trans_info,
541 today => DateTime->today,
542 currencies => scalar(SL::DB::Manager::Currency->get_all_sorted),
543 employees => $employees,
546 $main::lxdebug->leave_sub();
550 $main::lxdebug->enter_sub();
554 my $form = $main::form;
555 my %myconfig = %main::myconfig;
556 my $locale = $main::locale;
557 my $cgi = $::request->{cgi};
560 my $follow_ups = FU->follow_ups('trans_id' => $form->{id}, 'not_done' => 1);
561 if ( @{ $follow_ups} ) {
562 $form->{follow_up_length} = scalar(@{$follow_ups});
563 $form->{follow_up_due_length} = sum(map({ $_->{due} * 1 } @{ $follow_ups }));
567 print $::form->parse_html_template('ar/form_footer');
569 $main::lxdebug->leave_sub();
573 $::auth->assert('ar_transactions');
575 SL::DB::Invoice->new(id => $::form->{id})->load->mark_as_paid;
576 $::form->redirect($::locale->text("Marked as paid"));
580 $::form->{transdate} = DateTime->today_local->to_kivitendo if !$::form->{transdate};
581 $::form->{gldate} = $::form->{transdate} if !$::form->{gldate};
587 $main::lxdebug->enter_sub();
589 $main::auth->assert('ar_transactions');
591 my $form = $main::form;
592 my %myconfig = %main::myconfig;
596 my ($totaltax, $exchangerate);
598 $form->{invtotal} = 0;
600 delete @{ $form }{ grep { m/^tax_\d+$/ } keys %{ $form } };
602 map { $form->{$_} = $form->parse_amount(\%myconfig, $form->{$_}) }
603 qw(exchangerate creditlimit creditremaining);
605 my @flds = qw(amount AR_amount projectnumber oldprojectnumber project_id);
609 for my $i (1 .. $form->{rowcount}) {
610 $form->{"amount_$i"} = $form->parse_amount(\%myconfig, $form->{"amount_$i"});
611 if ($form->{"amount_$i"} || $params{keep_rows_without_amount}) {
614 my ($taxkey, $rate) = split(/--/, $form->{"taxchart_$i"});
617 ($tmpnetamount,$form->{"tax_$i"}) = $form->calculate_tax($form->{"amount_$i"},$rate,$form->{taxincluded},2);
619 $totaltax += $form->{"tax_$i"};
620 map { $a[$j]->{$_} = $form->{"${_}_$i"} } @flds;
625 $form->redo_rows(\@flds, \@a, $count, $form->{rowcount});
626 $form->{rowcount} = $count + ($params{dont_add_new_row} ? 0 : 1);
627 map { $form->{invtotal} += $form->{"amount_$_"} } (1 .. $form->{rowcount});
629 $form->{forex} = $form->check_exchangerate( \%myconfig, $form->{currency}, $form->{transdate}, 'buy');
630 $form->{exchangerate} = $form->{forex} if $form->{forex};
632 $form->{invdate} = $form->{transdate};
634 if (($form->{previous_customer_id} || $form->{customer_id}) != $form->{customer_id}) {
635 IS->get_customer(\%myconfig, $form);
636 if (($form->{rowcount} == 1) && ($form->{amount_1} == 0)) {
637 my $last_used_ar_chart = SL::DB::Customer->load_cached($form->{customer_id})->last_used_ar_chart;
638 $form->{"AR_amount_chart_id_1"} = $last_used_ar_chart->id if $last_used_ar_chart;
643 ($form->{taxincluded}) ? $form->{invtotal} : $form->{invtotal} + $totaltax;
645 for my $i (1 .. $form->{paidaccounts}) {
646 if ($form->parse_amount(\%myconfig, $form->{"paid_$i"})) {
649 $form->parse_amount(\%myconfig, $form->{"${_}_$i"})
650 } qw(paid exchangerate);
652 $form->{totalpaid} += $form->{"paid_$i"};
654 $form->{"forex_$i"} = $form->check_exchangerate( \%myconfig, $form->{currency}, $form->{"datepaid_$i"}, 'buy');
655 $form->{"exchangerate_$i"} = $form->{"forex_$i"} if $form->{"forex_$i"};
659 $form->{creditremaining} -=
660 ($form->{invtotal} - $form->{totalpaid} + $form->{oldtotalpaid} -
661 $form->{oldinvtotal});
662 $form->{oldinvtotal} = $form->{invtotal};
663 $form->{oldtotalpaid} = $form->{totalpaid};
667 $main::lxdebug->leave_sub();
671 # ToDO: fix $closedto and $invdate
674 $main::lxdebug->enter_sub();
676 $main::auth->assert('ar_transactions');
678 my $form = $main::form;
679 my %myconfig = %main::myconfig;
680 my $locale = $main::locale;
682 $form->mtime_ischanged('ar');
683 $form->{defaultcurrency} = $form->get_default_currency(\%myconfig);
685 my $invdate = $form->datetonum($form->{transdate}, \%myconfig);
687 for my $i (1 .. $form->{paidaccounts}) {
689 if ($form->parse_amount(\%myconfig, $form->{"paid_$i"})) {
690 my $datepaid = $form->datetonum($form->{"datepaid_$i"}, \%myconfig);
692 $form->isblank("datepaid_$i", $locale->text('Payment date missing!'));
694 $form->error($locale->text('Cannot post transaction above the maximum future booking date!'))
695 if ($form->date_max_future($form->{"datepaid_$i"}, \%myconfig));
697 #Zusätzlich noch das Buchungsdatum in die Bücherkontrolle einbeziehen
698 # (Dient zur Prüfung ob ZE oder ZA geprüft werden soll)
699 $form->error($locale->text('Cannot post payment for a closed period!'))
700 if ($form->date_closed($form->{"datepaid_$i"}) && !$form->date_closed($form->{"gldate_$i"}, \%myconfig));
702 if ($form->{defaultcurrency} && ($form->{currency} ne $form->{defaultcurrency})) {
703 # $form->{"exchangerate_$i"} = $form->{exchangerate} if ($invdate == $datepaid);
704 $form->isblank("exchangerate_$i", $locale->text('Exchangerate for payment missing!'));
709 ($form->{AR}) = split /--/, $form->{AR};
710 ($form->{AR_paid}) = split /--/, $form->{AR_paid};
711 if (AR->post_payment(\%myconfig, \%$form)) {
712 $form->{snumbers} = qq|invnumber_| . $form->{invnumber};
713 $form->{what_done} = 'invoice';
714 $form->{addition} = "PAYMENT POSTED";
716 $form->redirect($locale->text('Payment posted!'))
718 $form->error($locale->text('Cannot post payment!'));
721 $main::lxdebug->leave_sub();
726 $main::auth->assert('ar_transactions');
728 my $form = $main::form;
735 $main::lxdebug->enter_sub();
737 $main::auth->assert('ar_transactions');
739 my $form = $main::form;
740 my %myconfig = %main::myconfig;
741 my $locale = $main::locale;
745 $form->mtime_ischanged('ar');
749 # check if there is an invoice number, invoice and due date
750 $form->isblank("transdate", $locale->text('Invoice Date missing!'));
751 $form->isblank("duedate", $locale->text('Due Date missing!'));
752 $form->isblank("customer_id", $locale->text('Customer missing!'));
754 if ($myconfig{mandatory_departments} && !$form->{department_id}) {
755 $form->{saved_message} = $::locale->text('You have to specify a department.');
760 my $closedto = $form->datetonum($form->{closedto}, \%myconfig);
761 my $transdate = $form->datetonum($form->{transdate}, \%myconfig);
763 $form->error($locale->text('Cannot post transaction above the maximum future booking date!'))
764 if ($form->date_max_future($transdate, \%myconfig));
766 $form->error($locale->text('Cannot post transaction for a closed period!')) if ($form->date_closed($form->{"transdate"}, \%myconfig));
768 $form->error($locale->text('Zero amount posting!'))
769 unless grep $_*1, map $form->parse_amount(\%myconfig, $form->{"amount_$_"}), 1..$form->{rowcount};
771 $form->isblank("exchangerate", $locale->text('Exchangerate missing!'))
772 if ($form->{defaultcurrency} && ($form->{currency} ne $form->{defaultcurrency}));
776 for my $i (1 .. $form->{paidaccounts}) {
777 if ($form->parse_amount(\%myconfig, $form->{"paid_$i"})) {
778 $datepaid = $form->datetonum($form->{"datepaid_$i"}, \%myconfig);
780 $form->isblank("datepaid_$i", $locale->text('Payment date missing!'));
782 $form->error($locale->text('Cannot post transaction above the maximum future booking date!'))
783 if ($form->date_max_future($form->{"datepaid_$i"}, \%myconfig));
785 #Zusätzlich noch das Buchungsdatum in die Bücherkontrolle einbeziehen
786 # (Dient zur Prüfung ob ZE oder ZA geprüft werden soll)
787 $form->error($locale->text('Cannot post payment for a closed period!'))
788 if ($form->date_closed($form->{"datepaid_$i"}) && !$form->date_closed($form->{"gldate_$i"}, \%myconfig));
790 if ($form->{defaultcurrency} && ($form->{currency} ne $form->{defaultcurrency})) {
791 $form->{"exchangerate_$i"} = $form->{exchangerate} if ($transdate == $datepaid);
792 $form->isblank("exchangerate_$i", $locale->text('Exchangerate for payment missing!'));
797 # if oldcustomer ne customer redo form
798 if (($form->{previous_customer_id} || $form->{customer_id}) != $form->{customer_id}) {
800 $::dispatcher->end_request;
803 $form->{AR}{receivables} = $form->{ARselected};
806 $form->{id} = 0 if $form->{postasnew};
807 $form->error($locale->text('Cannot post transaction!')) unless AR->post_transaction(\%myconfig, \%$form);
810 if(!exists $form->{addition} && $form->{id} ne "") {
811 $form->{snumbers} = "invnumber_$form->{invnumber}";
812 $form->{what_done} = "invoice";
813 $form->{addition} = "POSTED";
816 # /saving the history
818 $form->redirect($locale->text('AR transaction posted.') . ' ' . $locale->text('ID') . ': ' . $form->{id}) unless $inline;
820 $main::lxdebug->leave_sub();
824 $main::lxdebug->enter_sub();
826 $main::auth->assert('ar_transactions');
828 my $form = $main::form;
829 my %myconfig = %main::myconfig;
831 $form->{postasnew} = 1;
833 if(!exists $form->{addition} && $form->{id} ne "") {
834 $form->{snumbers} = qq|invnumber_| . $form->{invnumber};
835 $form->{what_done} = "invoice";
836 $form->{addition} = "POSTED AS NEW";
839 # /saving the history
842 $main::lxdebug->leave_sub();
846 $main::lxdebug->enter_sub();
848 $main::auth->assert('ar_transactions');
850 my $form = $main::form;
851 my %myconfig = %main::myconfig;
853 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);
854 $form->{paidaccounts} = 1;
857 my $today = DateTime->today_local;
858 $form->{transdate} = $today->to_kivitendo;
859 $form->{duedate} = $form->{transdate};
861 if ($form->{customer_id}) {
862 my $payment_terms = SL::DB::Customer->load_cached($form->{customer_id})->payment;
863 $form->{duedate} = $payment_terms->calc_date(reference_date => $today)->to_kivitendo if $payment_terms;
868 $main::lxdebug->leave_sub();
872 $::auth->assert('ar_transactions');
874 my $form = $main::form;
875 my %myconfig = %main::myconfig;
876 my $locale = $main::locale;
878 if (AR->delete_transaction(\%myconfig, \%$form)) {
880 if(!exists $form->{addition}) {
881 $form->{snumbers} = qq|invnumber_| . $form->{invnumber};
882 $form->{what_done} = "invoice";
883 $form->{addition} = "DELETED";
886 # /saving the history
887 $form->redirect($locale->text('Transaction deleted!'));
889 $form->error($locale->text('Cannot delete transaction!'));
892 sub setup_ar_search_action_bar {
895 for my $bar ($::request->layout->get('actionbar')) {
898 $::locale->text('Search'),
899 submit => [ '#form' ],
900 checks => [ 'kivi.validate_form' ],
901 accesskey => 'enter',
905 $::request->layout->add_javascripts('kivi.Validator.js');
908 sub setup_ar_transactions_action_bar {
910 my $may_edit_create = $::auth->assert('invoice_edit', 1);
912 for my $bar ($::request->layout->get('actionbar')) {
915 $::locale->text('Print'),
916 call => [ 'kivi.MassInvoiceCreatePrint.showMassPrintOptionsOrDownloadDirectly' ],
917 disabled => !$may_edit_create ? t8('You do not have the permissions to access this function.')
918 : !$params{num_rows} ? $::locale->text('The report doesn\'t contain entries.')
923 action => [ $::locale->text('Create new') ],
925 $::locale->text('AR Transaction'),
926 submit => [ '#create_new_form', { action => 'ar_transaction' } ],
927 disabled => !$may_edit_create ? t8('You do not have the permissions to access this function.') : undef,
930 $::locale->text('Sales Invoice'),
931 submit => [ '#create_new_form', { action => 'sales_invoice' } ],
932 disabled => !$may_edit_create ? t8('You do not have the permissions to access this function.') : undef,
934 ], # end of combobox "Create new"
940 $main::lxdebug->enter_sub();
942 my $form = $main::form;
943 my %myconfig = %main::myconfig;
944 my $locale = $main::locale;
945 my $cgi = $::request->{cgi};
947 $form->{title} = $locale->text('Invoices, Credit Notes & AR Transactions');
949 $form->{ALL_EMPLOYEES} = SL::DB::Manager::Employee->get_all_sorted(query => [ deleted => 0 ]);
950 $form->{ALL_DEPARTMENTS} = SL::DB::Manager::Department->get_all_sorted;
951 $form->{ALL_BUSINESS_TYPES} = SL::DB::Manager::Business->get_all_sorted;
953 $form->{CT_CUSTOM_VARIABLES} = CVar->get_configs('module' => 'CT');
954 ($form->{CT_CUSTOM_VARIABLES_FILTER_CODE},
955 $form->{CT_CUSTOM_VARIABLES_INCLUSION_CODE}) = CVar->render_search_options('variables' => $form->{CT_CUSTOM_VARIABLES},
956 'include_prefix' => 'l_',
957 'include_value' => 'Y');
959 # constants and subs for template
960 $form->{vc_keys} = sub { "$_[0]->{name}--$_[0]->{id}" };
962 $::request->layout->add_javascripts("autocomplete_project.js");
964 setup_ar_search_action_bar();
967 print $form->parse_html_template('ar/search', { %myconfig });
969 $main::lxdebug->leave_sub();
972 sub create_subtotal_row {
973 $main::lxdebug->enter_sub();
975 my ($totals, $columns, $column_alignment, $subtotal_columns, $class) = @_;
977 my $form = $main::form;
978 my %myconfig = %main::myconfig;
980 my $row = { map { $_ => { 'data' => '', 'class' => $class, 'align' => $column_alignment->{$_}, } } @{ $columns } };
982 map { $row->{$_}->{data} = $form->format_amount(\%myconfig, $totals->{$_}, 2) } @{ $subtotal_columns };
984 $row->{tax}->{data} = $form->format_amount(\%myconfig, $totals->{amount} - $totals->{netamount}, 2);
986 map { $totals->{$_} = 0 } @{ $subtotal_columns };
988 $main::lxdebug->leave_sub();
993 sub ar_transactions {
994 $main::lxdebug->enter_sub();
996 my $form = $main::form;
997 my %myconfig = %main::myconfig;
998 my $locale = $main::locale;
1000 my ($callback, $href, @columns);
1002 report_generator_set_default_sort('transdate', 1);
1004 AR->ar_transactions(\%myconfig, \%$form);
1006 $form->{title} = $locale->text('Invoices, Credit Notes & AR Transactions');
1008 my $report = SL::ReportGenerator->new(\%myconfig, $form);
1011 qw(ids transdate id type invnumber ordnumber cusordnumber name netamount tax amount paid
1012 datepaid due duedate transaction_description notes salesman employee shippingpoint shipvia
1013 marge_total marge_percent globalprojectnumber customernumber country ustid taxzone
1014 payment_terms charts customertype direct_debit dunning_description department);
1016 my $ct_cvar_configs = CVar->get_configs('module' => 'CT');
1017 my @ct_includeable_custom_variables = grep { $_->{includeable} } @{ $ct_cvar_configs };
1018 my @ct_searchable_custom_variables = grep { $_->{searchable} } @{ $ct_cvar_configs };
1020 my %column_defs_cvars = map { +"cvar_$_->{name}" => { 'text' => $_->{description} } } @ct_includeable_custom_variables;
1021 push @columns, map { "cvar_$_->{name}" } @ct_includeable_custom_variables;
1023 my @hidden_variables = map { "l_${_}" } @columns;
1024 push @hidden_variables, "l_subtotal", qw(open closed customer invnumber ordnumber cusordnumber transaction_description notes project_id transdatefrom transdateto duedatefrom duedateto
1025 employee_id salesman_id business_id parts_partnumber parts_description department_id show_marked_as_closed show_not_mailed);
1026 push @hidden_variables, map { "cvar_$_->{name}" } @ct_searchable_custom_variables;
1028 $href = build_std_url('action=ar_transactions', grep { $form->{$_} } @hidden_variables);
1031 'ids' => { raw_header_data => SL::Presenter::Tag::checkbox_tag("", id => "check_all", checkall => "[data-checkall=1]"), align => 'center' },
1032 'transdate' => { 'text' => $locale->text('Date'), },
1033 'id' => { 'text' => $locale->text('ID'), },
1034 'type' => { 'text' => $locale->text('Type'), },
1035 'invnumber' => { 'text' => $locale->text('Invoice'), },
1036 'ordnumber' => { 'text' => $locale->text('Order'), },
1037 'cusordnumber' => { 'text' => $locale->text('Customer Order Number'), },
1038 'name' => { 'text' => $locale->text('Customer'), },
1039 'netamount' => { 'text' => $locale->text('Amount'), },
1040 'tax' => { 'text' => $locale->text('Tax'), },
1041 'amount' => { 'text' => $locale->text('Total'), },
1042 'paid' => { 'text' => $locale->text('Paid'), },
1043 'datepaid' => { 'text' => $locale->text('Date Paid'), },
1044 'due' => { 'text' => $locale->text('Amount Due'), },
1045 'duedate' => { 'text' => $locale->text('Due Date'), },
1046 'transaction_description' => { 'text' => $locale->text('Transaction description'), },
1047 'notes' => { 'text' => $locale->text('Notes'), },
1048 'salesman' => { 'text' => $locale->text('Salesperson'), },
1049 'employee' => { 'text' => $locale->text('Employee'), },
1050 'shippingpoint' => { 'text' => $locale->text('Shipping Point'), },
1051 'shipvia' => { 'text' => $locale->text('Ship via'), },
1052 'globalprojectnumber' => { 'text' => $locale->text('Document Project Number'), },
1053 'marge_total' => { 'text' => $locale->text('Ertrag'), },
1054 'marge_percent' => { 'text' => $locale->text('Ertrag prozentual'), },
1055 'customernumber' => { 'text' => $locale->text('Customer Number'), },
1056 'country' => { 'text' => $locale->text('Country'), },
1057 'ustid' => { 'text' => $locale->text('USt-IdNr.'), },
1058 'taxzone' => { 'text' => $locale->text('Steuersatz'), },
1059 'payment_terms' => { 'text' => $locale->text('Payment Terms'), },
1060 'charts' => { 'text' => $locale->text('Chart'), },
1061 'customertype' => { 'text' => $locale->text('Customer type'), },
1062 'direct_debit' => { 'text' => $locale->text('direct debit'), },
1063 'department' => { 'text' => $locale->text('Department'), },
1064 dunning_description => { 'text' => $locale->text('Dunning level'), },
1068 foreach my $name (qw(id transdate duedate invnumber ordnumber cusordnumber name datepaid employee shippingpoint shipvia transaction_description direct_debit department)) {
1069 my $sortdir = $form->{sort} eq $name ? 1 - $form->{sortdir} : $form->{sortdir};
1070 $column_defs{$name}->{link} = $href . "&sort=$name&sortdir=$sortdir";
1073 my %column_alignment = map { $_ => 'right' } qw(netamount tax amount paid due);
1075 $form->{"l_type"} = "Y";
1076 map { $column_defs{$_}->{visible} = $form->{"l_${_}"} ? 1 : 0 } @columns;
1078 $column_defs{ids}->{visible} = 'HTML';
1080 $report->set_columns(%column_defs);
1081 $report->set_column_order(@columns);
1083 $report->set_export_options('ar_transactions', @hidden_variables, qw(sort sortdir));
1085 $report->set_sort_indicator($form->{sort}, $form->{sortdir});
1087 CVar->add_custom_variables_to_report('module' => 'CT',
1088 'trans_id_field' => 'customer_id',
1089 'configs' => $ct_cvar_configs,
1090 'column_defs' => \%column_defs,
1091 'data' => $form->{AR});
1094 if ($form->{customer}) {
1095 push @options, $locale->text('Customer') . " : $form->{customer}";
1097 if ($form->{cp_name}) {
1098 push @options, $locale->text('Contact Person') . " : $form->{cp_name}";
1101 if ($form->{department_id}) {
1102 my $department = SL::DB::Manager::Department->find_by( id => $form->{department_id} );
1103 push @options, $locale->text('Department') . " : " . $department->description;
1105 if ($form->{invnumber}) {
1106 push @options, $locale->text('Invoice Number') . " : $form->{invnumber}";
1108 if ($form->{ordnumber}) {
1109 push @options, $locale->text('Order Number') . " : $form->{ordnumber}";
1111 if ($form->{cusordnumber}) {
1112 push @options, $locale->text('Customer Order Number') . " : $form->{cusordnumber}";
1114 if ($form->{notes}) {
1115 push @options, $locale->text('Notes') . " : $form->{notes}";
1117 if ($form->{transaction_description}) {
1118 push @options, $locale->text('Transaction description') . " : $form->{transaction_description}";
1120 if ($form->{parts_partnumber}) {
1121 push @options, $locale->text('Part Number') . " : $form->{parts_partnumber}";
1123 if ($form->{parts_description}) {
1124 push @options, $locale->text('Part Description') . " : $form->{parts_description}";
1126 if ($form->{transdatefrom}) {
1127 push @options, $locale->text('From') . " " . $locale->date(\%myconfig, $form->{transdatefrom}, 1);
1129 if ($form->{transdateto}) {
1130 push @options, $locale->text('Bis') . " " . $locale->date(\%myconfig, $form->{transdateto}, 1);
1132 if ($form->{open}) {
1133 push @options, $locale->text('Open');
1135 if ($form->{employee_id}) {
1136 my $employee = SL::DB::Employee->new(id => $form->{employee_id})->load;
1137 push @options, $locale->text('Employee') . ' : ' . $employee->name;
1139 if ($form->{salesman_id}) {
1140 my $salesman = SL::DB::Employee->new(id => $form->{salesman_id})->load;
1141 push @options, $locale->text('Salesman') . ' : ' . $salesman->name;
1143 if ($form->{closed}) {
1144 push @options, $locale->text('Closed');
1147 $form->{ALL_PRINTERS} = SL::DB::Manager::Printer->get_all_sorted;
1149 $report->set_options('top_info_text' => join("\n", @options),
1150 'raw_top_info_text' => $form->parse_html_template('ar/ar_transactions_header'),
1151 'raw_bottom_info_text' => $form->parse_html_template('ar/ar_transactions_bottom'),
1152 'output_format' => 'HTML',
1153 'title' => $form->{title},
1154 'attachment_basename' => $locale->text('invoice_list') . strftime('_%Y%m%d', localtime time),
1156 $report->set_options_from_form();
1157 $locale->set_numberformat_wo_thousands_separator(\%myconfig) if lc($report->{options}->{output_format}) eq 'csv';
1159 # add sort and escape callback, this one we use for the add sub
1160 $form->{callback} = $href .= "&sort=$form->{sort}";
1162 # escape callback for href
1163 $callback = $form->escape($href);
1165 my @subtotal_columns = qw(netamount amount paid due marge_total marge_percent);
1167 my %totals = map { $_ => 0 } @subtotal_columns;
1168 my %subtotals = map { $_ => 0 } @subtotal_columns;
1172 foreach my $ar (@{ $form->{AR} }) {
1173 $ar->{tax} = $ar->{amount} - $ar->{netamount};
1174 $ar->{due} = $ar->{amount} - $ar->{paid};
1176 map { $subtotals{$_} += $ar->{$_};
1177 $totals{$_} += $ar->{$_} } @subtotal_columns;
1179 $subtotals{marge_percent} = $subtotals{netamount} ? ($subtotals{marge_total} * 100 / $subtotals{netamount}) : 0;
1180 $totals{marge_percent} = $totals{netamount} ? ($totals{marge_total} * 100 / $totals{netamount} ) : 0;
1182 my $is_storno = $ar->{storno} && $ar->{storno_id};
1183 my $has_storno = $ar->{storno} && !$ar->{storno_id};
1186 $has_storno ? $locale->text("Invoice with Storno (abbreviation)") :
1187 $is_storno ? $locale->text("Storno (one letter abbreviation)") :
1188 $ar->{amount} < 0 ? $locale->text("Credit note (one letter abbreviation)") :
1189 $ar->{invoice} ? $locale->text("Invoice (one letter abbreviation)") :
1190 $locale->text("AR Transaction (abbreviation)");
1192 map { $ar->{$_} = $form->format_amount(\%myconfig, $ar->{$_}, 2) } qw(netamount tax amount paid due marge_total marge_percent);
1194 $ar->{direct_debit} = $ar->{direct_debit} ? $::locale->text('yes') : $::locale->text('no');
1198 foreach my $column (@columns) {
1200 'data' => $ar->{$column},
1201 'align' => $column_alignment{$column},
1205 $row->{invnumber}->{link} = build_std_url("script=" . ($ar->{invoice} ? 'is.pl' : 'ar.pl'), 'action=edit')
1206 . "&id=" . E($ar->{id}) . "&callback=${callback}";
1209 raw_data => SL::Presenter::Tag::checkbox_tag("id[]", value => $ar->{id}, "data-checkall" => 1),
1214 my $row_set = [ $row ];
1216 if (($form->{l_subtotal} eq 'Y')
1217 && (($idx == (scalar @{ $form->{AR} } - 1))
1218 || ($ar->{ $form->{sort} } ne $form->{AR}->[$idx + 1]->{ $form->{sort} }))) {
1219 push @{ $row_set }, create_subtotal_row(\%subtotals, \@columns, \%column_alignment, \@subtotal_columns, 'listsubtotal');
1222 $report->add_data($row_set);
1227 $report->add_separator();
1228 $report->add_data(create_subtotal_row(\%totals, \@columns, \%column_alignment, \@subtotal_columns, 'listtotal'));
1230 $::request->layout->add_javascripts('kivi.MassInvoiceCreatePrint.js');
1231 setup_ar_transactions_action_bar(num_rows => scalar(@{ $form->{AR} }));
1233 $report->generate_with_headers();
1235 $main::lxdebug->leave_sub();
1239 $main::lxdebug->enter_sub();
1241 $main::auth->assert('ar_transactions');
1243 my $form = $main::form;
1244 my %myconfig = %main::myconfig;
1245 my $locale = $main::locale;
1247 # don't cancel cancelled transactions
1248 if (IS->has_storno(\%myconfig, $form, 'ar')) {
1249 $form->{title} = $locale->text("Cancel Accounts Receivables Transaction");
1250 $form->error($locale->text("Transaction has already been cancelled!"));
1253 AR->storno($form, \%myconfig, $form->{id});
1255 # saving the history
1256 if(!exists $form->{addition} && $form->{id} ne "") {
1257 $form->{snumbers} = qq|invnumber_| . $form->{invnumber};
1258 $form->{addition} = "STORNO";
1259 $form->{what_done} = "invoice";
1260 $form->save_history;
1262 # /saving the history
1264 $form->redirect(sprintf $locale->text("Transaction %d cancelled."), $form->{storno_id});
1266 $main::lxdebug->leave_sub();
1269 sub setup_ar_form_header_action_bar {
1270 my $transdate = $::form->datetonum($::form->{transdate}, \%::myconfig);
1271 my $closedto = $::form->datetonum($::form->{closedto}, \%::myconfig);
1272 my $is_closed = $transdate <= $closedto;
1274 my $change_never = $::instance_conf->get_ar_changeable == 0;
1275 my $change_on_same_day_only = $::instance_conf->get_ar_changeable == 2 && ($::form->current_date(\%::myconfig) ne $::form->{gldate});
1277 my $is_storno = IS->is_storno(\%::myconfig, $::form, 'ar', $::form->{id});
1278 my $has_storno = IS->has_storno(\%::myconfig, $::form, 'ar');
1279 my $may_edit_create = $::auth->assert('ar_transactions', 1);
1281 my $is_linked_bank_transaction;
1283 && SL::DB::Default->get->payments_changeable != 0
1284 && SL::DB::Manager::BankTransactionAccTrans->find_by(ar_id => $::form->{id})) {
1286 $is_linked_bank_transaction = 1;
1288 for my $bar ($::request->layout->get('actionbar')) {
1292 submit => [ '#form', { action => "update" } ],
1293 id => 'update_button',
1294 checks => [ 'kivi.validate_form' ],
1295 disabled => !$may_edit_create ? t8('You must not change this AR transaction.') : undef,
1296 accesskey => 'enter',
1302 submit => [ '#form', { action => "post" } ],
1303 checks => [ 'kivi.validate_form', 'kivi.AR.check_fields_before_posting' ],
1304 disabled => !$may_edit_create ? t8('You must not change this AR transaction.')
1305 : $is_closed ? t8('The billing period has already been locked.')
1306 : $is_storno ? t8('A canceled invoice cannot be posted.')
1307 : ($::form->{id} && $change_never) ? t8('Changing invoices has been disabled in the configuration.')
1308 : ($::form->{id} && $change_on_same_day_only) ? t8('Invoices can only be changed on the day they are posted.')
1309 : $is_linked_bank_transaction ? t8('This transaction is linked with a bank transaction. Please undo and redo the bank transaction booking if needed.')
1314 submit => [ '#form', { action => "post_payment" } ],
1315 disabled => !$may_edit_create ? t8('You must not change this AR transaction.')
1316 : !$::form->{id} ? t8('This invoice has not been posted yet.')
1317 : $is_linked_bank_transaction ? t8('This transaction is linked with a bank transaction. Please undo and redo the bank transaction booking if needed.')
1320 action => [ t8('Mark as paid'),
1321 submit => [ '#form', { action => "mark_as_paid" } ],
1322 confirm => t8('This will remove the invoice from showing as unpaid even if the unpaid amount does not match the amount. Proceed?'),
1323 disabled => !$may_edit_create ? t8('You must not change this AR transaction.')
1324 : !$::form->{id} ? t8('This invoice has not been posted yet.')
1326 only_if => $::instance_conf->get_is_show_mark_as_paid,
1328 ], # end of combobox "Post"
1331 action => [ t8('Storno'),
1332 submit => [ '#form', { action => "storno" } ],
1333 checks => [ 'kivi.validate_form', 'kivi.AR.check_fields_before_posting' ],
1334 confirm => t8('Do you really want to cancel this invoice?'),
1335 disabled => !$may_edit_create ? t8('You must not change this AR transaction.')
1336 : !$::form->{id} ? t8('This invoice has not been posted yet.')
1337 : $has_storno ? t8('This invoice has been canceled already.')
1338 : $is_storno ? t8('Reversal invoices cannot be canceled.')
1339 : $::form->{totalpaid} ? t8('Invoices with payments cannot be canceled.')
1342 action => [ t8('Delete'),
1343 submit => [ '#form', { action => "delete" } ],
1344 confirm => t8('Do you really want to delete this object?'),
1345 disabled => !$may_edit_create ? t8('You must not change this AR transaction.')
1346 : !$::form->{id} ? t8('This invoice has not been posted yet.')
1347 : $change_never ? t8('Changing invoices has been disabled in the configuration.')
1348 : $change_on_same_day_only ? t8('Invoices can only be changed on the day they are posted.')
1349 : $is_closed ? t8('The billing period has already been locked.')
1352 ], # end of combobox "Storno"
1357 action => [ t8('Workflow') ],
1360 submit => [ '#form', { action => "use_as_new" } ],
1361 checks => [ 'kivi.validate_form' ],
1362 disabled => !$may_edit_create ? t8('You must not change this AR transaction.')
1363 : !$::form->{id} ? t8('This invoice has not been posted yet.')
1366 ], # end of combobox "Workflow"
1369 action => [ t8('more') ],
1372 call => [ 'set_history_window', $::form->{id} * 1, 'glid' ],
1373 disabled => !$::form->{id} ? t8('This invoice has not been posted yet.') : undef,
1377 call => [ 'follow_up_window' ],
1378 disabled => !$::form->{id} ? t8('This invoice has not been posted yet.') : undef,
1381 t8('Record templates'),
1382 call => [ 'kivi.RecordTemplate.popup', 'ar_transaction' ],
1383 disabled => !$may_edit_create ? t8('You must not change this AR transaction.') : undef,
1387 call => [ 'kivi.Draft.popup', 'ar', 'invoice', $::form->{draft_id}, $::form->{draft_description} ],
1388 disabled => !$may_edit_create ? t8('You must not change this AR transaction.')
1389 : $::form->{id} ? t8('This invoice has already been posted.')
1390 : $is_closed ? t8('The billing period has already been locked.')
1393 ], # end of combobox "more"
1396 $::request->layout->add_javascripts('kivi.Validator.js');