-
- $form->{title} |
-
-
-
-
-
-
-
-
-
- | . $locale->text('Customer') . qq| |
- $customer |
-
-
-
- {terms}>
-
-
- |
-
-
-
- | . $locale->text('Credit Limit') . qq| |
- $form->{creditlimit} |
- | . $locale->text('Remaining') . qq| |
- $form->{creditremaining} |
- {creditlimit}>
- {creditremaining}>
-
-
- |
-
-
- | . $locale->text('Currency') . qq| |
- |
-
- {defaultcurrency}>
- {fxgain_accno}>
- {fxloss_accno}>
- $exchangerate
-
- $department
- $taxincluded
-
- |
-
-
- |
-
-
- |
-
-
-
-
-
-$jsscript
-
-
-
- {rowcount}>
-|;
+ $::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");
- $form->{"tax"} = $form->format_amount(\%myconfig, $form->{"tax"}, 2);
+ my $transdate = $::form->{transdate} ? DateTime->from_kivitendo($::form->{transdate}) : DateTime->today_local;
+ my $first_taxchart;
- $amount = $locale->text('Amount');
- $project = $locale->text('Project');
+ my @transactions;
+ for my $i (1 .. $form->{rowcount}) {
+ my $transaction = {
+ amount => $form->{"amount_$i"},
+ tax => $form->{"tax_$i"},
+ project_id => ($i==$form->{rowcount}) ? $form->{globalproject_id} : $form->{"project_id_$i"},
+ };
- for $i (1 .. 1) {
+ my (%taxchart_labels, @taxchart_values, $default_taxchart, $taxchart_to_use);
+ my $amount_chart_id = $form->{"AR_amount_chart_id_$i"} // $default_ar_amount_chart_id;
+ my $chart_has_changed = $::form->{"previous_AR_amount_chart_id_$i"} && ($amount_chart_id != $::form->{"previous_AR_amount_chart_id_$i"});
- # format amounts
- $form->{"amount_$i"} =
- $form->format_amount(\%myconfig, $form->{"amount_$i"}, 2);
-
- print qq|
-
- $amount |
- {"amount_$i"}> |
- $project |
-
- {"project_id_$i"}>
- |
- |
-
-|;
- $amount = "";
- $project = "";
- }
+ foreach my $item ( GL->get_active_taxes_for_chart($amount_chart_id, $transdate) ) {
+ my $key = $item->id . "--" . $item->rate;
+ $first_taxchart //= $item;
+ $default_taxchart = $item if $item->{is_default};
+ $taxchart_to_use = $item if $key eq $form->{"taxchart_$i"};
- $taxlabel =
- ($form->{taxincluded})
- ? $locale->text('Tax Included')
- : $locale->text('Tax');
+ push(@taxchart_values, $key);
+ $taxchart_labels{$key} = $item->taxdescription . " " . $item->rate * 100 . ' %';
+ }
- print qq|
-
- $taxlabel |
- {"tax"}> |
- |
- |
- |
-
-|;
+ $taxchart_to_use = $default_taxchart // $first_taxchart if $chart_has_changed || !$taxchart_to_use;
+ my $selected_taxchart = $taxchart_to_use->id . '--' . $taxchart_to_use->rate;
- $form->{invtotal} = $form->format_amount(\%myconfig, $form->{invtotal}, 2);
+ $transaction->{selectAR_amount} =
+ $::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" : ""))
+ . $::request->presenter->hidden_tag("previous_AR_amount_chart_id_$i", $amount_chart_id);
- print qq|
-
-
- | . $locale->text('Total') . qq| |
- $form->{invtotal} |
-
- {oldinvtotal}>
- {oldtotalpaid}>
-
-
-
- |
- |
-
-
-
-
- | . $locale->text('Notes') . qq| |
- $notes |
-
-
- |
-
-
-
-
-
- |
- . $locale->text('Incoming Payments')
- . qq| |
-
-|;
+ $transaction->{taxchart} =
+ NTI($cgi->popup_menu('-name' => "taxchart_$i",
+ '-id' => "taxchart_$i",
+ '-style' => 'width:200px',
+ '-values' => \@taxchart_values,
+ '-labels' => \%taxchart_labels,
+ '-default' => $selected_taxchart));
- if ($form->{currency} eq $form->{defaultcurrency}) {
- @column_index = qw(datepaid source memo paid AR_paid);
- } else {
- @column_index = qw(datepaid source memo paid exchangerate AR_paid);
+ push @transactions, $transaction;
}
- $column_data{datepaid} = "" . $locale->text('Date') . " | ";
- $column_data{paid} = "" . $locale->text('Amount') . " | ";
- $column_data{exchangerate} = "" . $locale->text('Exch') . " | ";
- $column_data{AR_paid} = "" . $locale->text('Account') . " | ";
- $column_data{source} = "" . $locale->text('Source') . " | ";
- $column_data{memo} = "" . $locale->text('Memo') . " | ";
-
- print "
-
-";
- map { print "$column_data{$_}\n" } @column_index;
- print "
-
-";
+ $form->{invtotal_unformatted} = $form->{invtotal};
$form->{paidaccounts}++ if ($form->{"paid_$form->{paidaccounts}"});
- for $i (1 .. $form->{paidaccounts}) {
- print "
-
-";
-
- $form->{"selectAR_paid_$i"} = $form->{selectAR_paid};
- $form->{"selectAR_paid_$i"} =~
- s/option value=\"$form->{"AR_paid_$i"}\">/option value=\"$form->{"AR_paid_$i"}\" selected>/;
-
- # format amounts
- $form->{"paid_$i"} =
- $form->format_amount(\%myconfig, $form->{"paid_$i"}, 2);
- $form->{"exchangerate_$i"} =
- $form->format_amount(\%myconfig, $form->{"exchangerate_$i"});
-
- $exchangerate = qq| |;
- if ($form->{currency} ne $form->{defaultcurrency}) {
- if ($form->{"forex_$i"}) {
- $exchangerate =
- qq|{"exchangerate_$i"}>$form->{"exchangerate_$i"}|;
- } else {
- $exchangerate =
- qq|{"exchangerate_$i"}>|;
- }
- }
- $exchangerate .= qq|
-{"forex_$i"}>
-|;
+ my $now = $form->current_date(\%myconfig);
+
+ my @payments;
+ for my $i (1 .. $form->{paidaccounts}) {
+ my $payment = {
+ paid => $form->{"paid_$i"},
+ exchangerate => $form->{"exchangerate_$i"} || '',
+ gldate => $form->{"gldate_$i"},
+ acc_trans_id => $form->{"acc_trans_id_$i"},
+ source => $form->{"source_$i"},
+ memo => $form->{"memo_$i"},
+ AR_paid => $form->{"AR_paid_$i"},
+ forex => $form->{"forex_$i"},
+ datepaid => $form->{"datepaid_$i"},
+ paid_project_id => $form->{"paid_project_id_$i"},
+ gldate => $form->{"gldate_$i"},
+ };
+
+ # default account for current assets (i.e. 1801 - SKR04) if no account is selected
+ $form->{accno_arap} = IS->get_standard_accno_current_assets(\%myconfig, \%$form);
+
+ $payment->{selectAR_paid} =
+ NTI($cgi->popup_menu('-name' => "AR_paid_$i",
+ '-id' => "AR_paid_$i",
+ '-values' => \@AR_paid_values,
+ '-labels' => \%AR_paid_labels,
+ '-default' => $payment->{AR_paid} || $form->{accno_arap}));
+
+
+
+ $payment->{changeable} =
+ SL::DB::Default->get->payments_changeable == 0 ? !$payment->{acc_trans_id} # never
+ : SL::DB::Default->get->payments_changeable == 2 ? $payment->{gldate} eq '' || $payment->{gldate} eq $now
+ : 1;
+
+ #deaktivieren von gebuchten Zahlungen ausserhalb der Bücherkontrolle, vorher prüfen ob heute eingegeben
+ if ($form->date_closed($payment->{"gldate_$i"})) {
+ $payment->{changeable} = 0;
+ }
- $column_data{paid} =
- qq|{"paid_$i"}> | |;
- $column_data{AR_paid} =
- qq| | |;
- $column_data{exchangerate} = qq|$exchangerate | |;
- $column_data{datepaid} =
- qq|{"datepaid_$i"}> | |;
- $column_data{source} =
- qq| | |;
- $column_data{memo} =
- qq| | |;
-
- map { print qq|$column_data{$_}\n| } @column_index;
-
- print "
-
-";
+ push @payments, $payment;
}
- map { $form->{$_} =~ s/\"/"/g } qw(selectAR_paid);
- print qq|
-{paidaccounts}>
-
-
-
- |
-
-
-
|
-
-
-|;
- $lxdebug->leave_sub();
+ my @empty = grep { $_->{paid} eq '' } @payments;
+ @payments = (
+ (sort_by { DateTime->from_kivitendo($_->{datepaid}) } grep { $_->{paid} ne '' } @payments),
+ @empty,
+ );
+
+ $form->{totalpaid} = sum map { $_->{paid} } @payments;
+
+ my $employees = SL::DB::Manager::Employee->get_all_sorted(
+ where => [
+ or => [
+ (id => $::form->{employee_id}) x !!$::form->{employee_id},
+ deleted => undef,
+ deleted => 0,
+ ],
+ ],
+ );
+
+ $form->header;
+ print $::form->parse_html_template('ar/form_header', {
+ paid_missing => $::form->{invtotal} - $::form->{totalpaid},
+ show_exch => ($::form->{defaultcurrency} && ($::form->{currency} ne $::form->{defaultcurrency})),
+ payments => \@payments,
+ transactions => \@transactions,
+ project_labels => \%project_labels,
+ rows => $rows,
+ AR_chart_id => $form->{AR_chart_id},
+ title_str => $title,
+ follow_up_trans_info => $follow_up_trans_info,
+ today => DateTime->today,
+ currencies => scalar(SL::DB::Manager::Currency->get_all_sorted),
+ employees => $employees,
+ });
+
+ $main::lxdebug->leave_sub();
}
sub form_footer {
- $lxdebug->enter_sub();
-
- print qq|
+ $main::lxdebug->enter_sub();
-