-
- $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}>
-
-
-
-
- |
- . $locale->text('Account') . qq| |
- |
- . $locale->text('Amount') . qq| |
- |
- . $locale->text('Tax') . qq| |
- |
- . $locale->text('Korrektur') . qq| |
- |
- . $locale->text('Taxkey') . qq| |
- |
- . $locale->text('Project') . qq| |
-
-|;
+ $form->{paidaccounts}++ if ($form->{"paid_$form->{paidaccounts}"});
- $amount = $locale->text('Amount');
- $project = $locale->text('Project');
-
- for $i (1 .. $form->{rowcount}) {
-
- # format amounts
- $form->{"amount_$i"} =
- $form->format_amount(\%myconfig, $form->{"amount_$i"}, 2);
- $form->{"tax_$i"} = $form->format_amount(\%myconfig, $form->{"tax_$i"}, 2);
- $selectAR_amount = $selectAR_amount_unquoted;
- $selectAR_amount =~
- s/option value=\"$form->{"AR_amount_$i"}\"/option value=\"$form->{"AR_amount_$i"}\" selected/;
- $tax = $taxchart;
- $tax_selected = $form->{"taxchart_$i"};
- $tax =~ s/value=\"$tax_selected\"/value=\"$tax_selected\" selected/;
- $tax =
- qq| | |;
- $korrektur_checked = ($form->{"korrektur_$i"} ? 'checked' : '');
-
- my $projectnumber =
- NTI($cgi->popup_menu('-name' => "project_id_$i",
- '-values' => \@project_values,
- '-labels' => \%project_labels,
- '-default' => $form->{"project_id_$i"} ));
-
- print qq|
-
- |
- {"amount_$i"}> |
- {"tax_$i"}> |
- |
- $tax
- $projectnumber |
-
-|;
- $amount = "";
- $project = "";
+ 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' => \%chart_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;
+
+ push @payments, $payment;
}
- $form->{invtotal} = $form->format_amount(\%myconfig, $form->{invtotal}, 2);
+ $form->{totalpaid} = sum map { $_->{paid} } @payments;
- print qq|
-
-
-
- |
-
-
- |
-
- $form->{invtotal} |
-
- {oldinvtotal}>
- {oldtotalpaid}>
-
-
-
- |
-
-
-
-
- |
-
-
-
-
-
- | . $locale->text('Notes') . qq| |
- $notes |
-
-
- |
-
-
-
-
-
- |
- . $locale->text('Incoming Payments') . qq| |
-
-|;
+ $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,
+ ARselected => $ARselected,
+ title_str => $title,
+ follow_up_trans_info => $follow_up_trans_info,
+ });
+
+ $main::lxdebug->leave_sub();
+}
- if ($form->{currency} eq $form->{defaultcurrency}) {
- @column_index = qw(datepaid source memo paid AR_paid paid_project_id);
- } else {
- @column_index = qw(datepaid source memo paid exchangerate AR_paid paid_project_id);
- }
+sub form_footer {
+ $main::lxdebug->enter_sub();
- $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') . " | ";
- $column_data{paid_project_id} = "" . $locale->text('Project Number') . " | ";
-
- print "
-
-";
- map { print "$column_data{$_}\n" } @column_index;
- print "
-
-";
-
- my @triggers = ();
- $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
- if ($form->{"paid_$i"}) {
- $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"}>|;
- }
- }
+ $main::auth->assert('general_ledger');
- $exchangerate .= qq|
-{"forex_$i"}>
-|;
+ my $form = $main::form;
+ my %myconfig = %main::myconfig;
+ my $locale = $main::locale;
+ my $cgi = $::request->{cgi};
- $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| | |;
-
- $column_data{paid_project_id} =
- qq||
- . NTI($cgi->popup_menu('-name' => "paid_project_id_$i",
- '-values' => \@project_values,
- '-labels' => \%project_labels,
- '-default' => $form->{"paid_project_id_$i"} ))
- . qq| | |;
-
- map { print qq|$column_data{$_}\n| } @column_index;
-
- print "
-
-";
- push(@triggers, "datepaid_$i", "BL", "trigger_datepaid_$i");
+ if ( $form->{id} ) {
+ my $follow_ups = FU->follow_ups('trans_id' => $form->{id});
+ if ( @{ $follow_ups} ) {
+ $form->{follow_up_length} = scalar(@{$follow_ups});
+ $form->{follow_up_due_length} = sum(map({ $_->{due} * 1 } @{ $follow_ups }));
+ }
}
- map { $form->{$_} =~ s/\"/"/g } qw(selectAR_paid);
-
- print $form->write_trigger(\%myconfig, scalar(@triggers) / 3, @triggers) .
- qq|
-{paidaccounts}>
-
-
-
- |
-
-
-
|
-
-
-|;
- $lxdebug->leave_sub();
-}
+ my $transdate = $form->datetonum($form->{transdate}, \%myconfig);
+ my $closedto = $form->datetonum($form->{closedto}, \%myconfig);
-sub form_footer {
- $lxdebug->enter_sub();
+ $form->{is_closed} = $transdate <= $closedto;
- print qq|
+ # ToDO: - insert a global check for stornos, so that a storno is only possible a limited time after saving it
+ $form->{show_storno_button} =
+ $form->{id} &&
+ !IS->has_storno(\%myconfig, $form, 'ar') &&
+ !IS->is_storno(\%myconfig, $form, 'ar') &&
+ ($form->{totalpaid} == 0 || $form->{totalpaid} eq "");
-