X-Git-Url: http://wagnertech.de/git?a=blobdiff_plain;f=bin%2Fmozilla%2Far.pl;h=a6e122067512ee8e52fa1535fc68e9ed24969d13;hb=772ec8725a6da1fd25a9e256d16e44b4c5231904;hp=d6f91e99f882746e14ad3e1edf79dcf2b55fd6b3;hpb=755dcacefa2cf4e73b50402b20a9a2e1febed97d;p=kivitendo-erp.git diff --git a/bin/mozilla/ar.pl b/bin/mozilla/ar.pl index d6f91e99f..a6e122067 100644 --- a/bin/mozilla/ar.pl +++ b/bin/mozilla/ar.pl @@ -31,18 +31,22 @@ # #====================================================================== +use POSIX qw(strftime); +use List::Util qw(sum first); + use SL::AR; +use SL::FU; use SL::IS; use SL::PE; -use Data::Dumper; +use SL::ReportGenerator; require "bin/mozilla/arap.pl"; require "bin/mozilla/common.pl"; require "bin/mozilla/drafts.pl"; +require "bin/mozilla/reportgenerator.pl"; -1; - -# end of main +use strict; +#use warnings; # this is for our long dates # $locale->text('January') @@ -73,33 +77,41 @@ require "bin/mozilla/drafts.pl"; # $locale->text('Dec') sub add { - $lxdebug->enter_sub(); + $main::lxdebug->enter_sub(); - return $lxdebug->leave_sub() if (load_draft_maybe()); + $main::auth->assert('general_ledger'); + + my $form = $main::form; + my %myconfig = %main::myconfig; + + return $main::lxdebug->leave_sub() if (load_draft_maybe()); # saving the history if(!exists $form->{addition} && ($form->{id} ne "")) { $form->{snumbers} = qq|invnumber_| . $form->{invnumber}; - $form->{addition} = "ADDED"; - $form->save_history($form->dbconnect(\%myconfig)); + $form->{addition} = "ADDED"; + $form->save_history; } - # /saving the history - + # /saving the history + $form->{title} = "Add"; - $form->{callback} = - "$form->{script}?action=add&login=$form->{login}&password=$form->{password}" - unless $form->{callback}; + $form->{callback} = "ar.pl?action=add&DONT_LOAD_DRAFT=1" unless $form->{callback}; AR->get_transdate(\%myconfig, $form); $form->{initial_transdate} = $form->{transdate}; &create_links; $form->{transdate} = $form->{initial_transdate}; &display_form; - $lxdebug->leave_sub(); + $main::lxdebug->leave_sub(); } sub edit { - $lxdebug->enter_sub(); + $main::lxdebug->enter_sub(); + + $main::auth->assert('general_ledger'); + + my $form = $main::form; + # show history button $form->{javascript} = qq||; #/show hhistory button @@ -109,20 +121,31 @@ sub edit { &create_links; &display_form; - $lxdebug->leave_sub(); + $main::lxdebug->leave_sub(); } sub display_form { - $lxdebug->enter_sub(); + $main::lxdebug->enter_sub(); + + $main::auth->assert('general_ledger'); + + my $form = $main::form; &form_header; &form_footer; - $lxdebug->leave_sub(); + $main::lxdebug->leave_sub(); } sub create_links { - $lxdebug->enter_sub(); + $main::lxdebug->enter_sub(); + + $main::auth->assert('general_ledger'); + + my $form = $main::form; + my %myconfig = %main::myconfig; + + my ($duedate, $taxincluded); $form->create_links("AR", \%myconfig, "customer"); $duedate = $form->{duedate}; @@ -141,158 +164,65 @@ sub create_links { $form->{notes} = $form->{intnotes} unless $form->{notes}; # currencies - @curr = split(/:/, $form->{currencies}); - chomp $curr[0]; - $form->{defaultcurrency} = $curr[0]; + $form->{defaultcurrency} = $form->get_default_currency(\%myconfig); - map { $form->{selectcurrency} .= "$_\n" } @curr; + map { $form->{selectcurrency} .= "$_\n" } $form->get_all_currencies(\%myconfig); # customers - if (@{ $form->{all_customer} }) { + if (@{ $form->{all_customer} || [] }) { $form->{customer} = "$form->{customer}--$form->{customer_id}"; map { $form->{selectcustomer} .= "$_->{name}--$_->{id}\n" } (@{ $form->{all_customer} }); } # departments - if (@{ $form->{all_departments} }) { + if (@{ $form->{all_departments} || [] }) { $form->{selectdepartment} = "\n"; $form->{department} = "$form->{department}--$form->{department_id}"; map { $form->{selectdepartment} .= "$_->{description}--$_->{id}\n" - } (@{ $form->{all_departments} }); + } (@{ $form->{all_departments} || [] }); } $form->{employee} = "$form->{employee}--$form->{employee_id}"; # sales staff - if (@{ $form->{all_employees} }) { + if (@{ $form->{all_employees} || [] }) { $form->{selectemployee} = ""; map { $form->{selectemployee} .= "$_->{name}--$_->{id}\n" } - (@{ $form->{all_employees} }); + (@{ $form->{all_employees} || [] }); } # build the popup menus $form->{taxincluded} = ($form->{id}) ? $form->{taxincluded} : "checked"; - # forex - $form->{forex} = $form->{exchangerate}; - $exchangerate = ($form->{exchangerate}) ? $form->{exchangerate} : 1; - foreach $key (keys %{ $form->{AR_links} }) { - # if there is a value we have an old entry - my $j = 0; - my $k = 0; - - for $i (1 .. scalar @{ $form->{acc_trans}{$key} }) { - if ($key eq "AR_paid") { - $j++; - $form->{"AR_paid_$j"} = $form->{acc_trans}{$key}->[$i-1]->{accno}; - - # reverse paid - $form->{"paid_$j"} = $form->{acc_trans}{$key}->[$i - 1]->{amount} * -1; - $form->{"datepaid_$j"} = - $form->{acc_trans}{$key}->[$i - 1]->{transdate}; - $form->{"source_$j"} = $form->{acc_trans}{$key}->[$i - 1]->{source}; - $form->{"memo_$j"} = $form->{acc_trans}{$key}->[$i - 1]->{memo}; - - $form->{"forex_$j"} = $form->{"exchangerate_$i"} = - $form->{acc_trans}{$key}->[$i - 1]->{exchangerate}; - $form->{"paid_project_id_$j"} = $form->{acc_trans}{$key}->[$i - 1]->{project_id}; - $form->{paidaccounts}++; - - } else { - - $akey = $key; - $akey =~ s/AR_//; - - if ($key eq "AR_tax" || $key eq "AP_tax") { - $form->{"${key}_$form->{acc_trans}{$key}->[$i-1]->{accno}"} = - "$form->{acc_trans}{$key}->[$i-1]->{accno}--$form->{acc_trans}{$key}->[$i-1]->{description}"; - $form->{"${akey}_$form->{acc_trans}{$key}->[$i-1]->{accno}"} = - $form->round_amount( - $form->{acc_trans}{$key}->[$i - 1]->{amount} / $exchangerate, - 2); - - if ($form->{"$form->{acc_trans}{$key}->[$i-1]->{accno}_rate"} > 0) { - $totaltax += - $form->{"${akey}_$form->{acc_trans}{$key}->[$i-1]->{accno}"}; - $taxrate += - $form->{"$form->{acc_trans}{$key}->[$i-1]->{accno}_rate"}; - } else { - $totalwithholding += - $form->{"${akey}_$form->{acc_trans}{$key}->[$i-1]->{accno}"}; - $withholdingrate += - $form->{"$form->{acc_trans}{$key}->[$i-1]->{accno}_rate"}; - } - $index = $form->{acc_trans}{$key}->[$i - 1]->{index}; - $form->{"tax_$index"} = $form->{acc_trans}{$key}->[$i - 1]->{amount}; - $totaltax += $form->{"tax_$index"}; - - } else { - $k++; - $form->{"${akey}_$k"} = - $form->round_amount( - $form->{acc_trans}{$key}->[$i - 1]->{amount} / $exchangerate, - 2); - if ($akey eq 'amount') { - $form->{rowcount}++; - $totalamount += $form->{"${akey}_$i"}; - - $form->{"oldprojectnumber_$k"} = $form->{"projectnumber_$k"} = - "$form->{acc_trans}{$key}->[$i-1]->{projectnumber}"; - $form->{taxrate} = $form->{acc_trans}{$key}->[$i - 1]->{rate}; - $form->{"project_id_$k"} = - "$form->{acc_trans}{$key}->[$i-1]->{project_id}"; - } - $form->{"${key}_$i"} = - "$form->{acc_trans}{$key}->[$i-1]->{accno}--$form->{acc_trans}{$key}->[$i-1]->{description}"; - - if ($akey eq "AR") { - $form->{ARselected} = $form->{acc_trans}{$key}->[$i-1]->{accno}; - - } elsif ($akey eq "amount") { - $form->{"${key}_$k"} = $form->{acc_trans}{$key}->[$i-1]->{accno} . - "--" . $form->{acc_trans}{$key}->[$i-1]->{id}; - $form->{"taxchart_$k"} = $form->{acc_trans}{$key}->[$i-1]->{id} . - "--" . $form->{acc_trans}{$key}->[$i-1]->{rate}; - } - } - } - } - } - - $form->{taxincluded} = $taxincluded if ($form->{id}); - $form->{paidaccounts} = 1 if not defined $form->{paidaccounts}; - - if ($form->{taxincluded} && $form->{taxrate} && $totalamount) { - - # add tax to amounts and invtotal - for $i (1 .. $form->{rowcount}) { - $taxamount = - ($totaltax + $totalwithholding) * $form->{"amount_$i"} / $totalamount; - $tax = $form->round_amount($taxamount, 2); - $diff += ($taxamount - $tax); - $form->{"amount_$i"} += $form->{"tax_$i"}; - } - $form->{amount_1} += $form->round_amount($diff, 2); - } - - $taxamount = $form->round_amount($taxamount, 2); - $form->{tax} = $taxamount; - - $form->{invtotal} = $totalamount + $totaltax; + AR->setup_form($form); $form->{locked} = ($form->datetonum($form->{transdate}, \%myconfig) <= $form->datetonum($form->{closedto}, \%myconfig)); - $lxdebug->leave_sub(); + $main::lxdebug->leave_sub(); } sub form_header { - $lxdebug->enter_sub(); + $main::lxdebug->enter_sub(); + + $main::auth->assert('general_ledger'); + + my $form = $main::form; + my %myconfig = %main::myconfig; + my $locale = $main::locale; + my $cgi = $::request->{cgi}; + + my ($title, $readonly, $exchangerate, $rows); + my ($taxincluded, $notes, $department, $customer, $employee, $amount, $project); + my ($jsscript, $button1, $button2, $onload); + my ($selectAR_amount, $selectAR_paid, $ARselected, $tax); + my (@column_index, %column_data); + $title = $form->{title}; $form->{title} = $locale->text("$title Accounts Receivables Transaction"); @@ -331,29 +261,28 @@ sub form_header { $readonly = ($form->{radier}) ? "" : $readonly; # set option selected - foreach $item (qw(customer currency department employee)) { + foreach my $item (qw(customer currency department employee)) { $form->{"select$item"} =~ s/ selected//; $form->{"select$item"} =~ s/option>\Q$form->{$item}\E/option selected>$form->{$item}/; } - # format amounts - $form->{exchangerate} = - $form->format_amount(\%myconfig, $form->{exchangerate}); + $form->{forex} = $form->check_exchangerate( \%myconfig, $form->{currency}, $form->{transdate}, 'buy'); + $form->{exchangerate} = $form->{forex} if $form->{forex}; - $form->{creditlimit} = - $form->format_amount(\%myconfig, $form->{creditlimit}, 0, "0"); - $form->{creditremaining} = - $form->format_amount(\%myconfig, $form->{creditremaining}, 0, "0"); + # format amounts + $form->{exchangerate} = $form->{exchangerate} ? $form->format_amount(\%myconfig, $form->{exchangerate}) : ''; + $form->{creditlimit} = $form->format_amount(\%myconfig, $form->{creditlimit}, 0, "0"); + $form->{creditremaining} = $form->format_amount(\%myconfig, $form->{creditremaining}, 0, "0"); $exchangerate = qq| {forex}> |; - if ($form->{currency} ne $form->{defaultcurrency}) { + if ($form->{defaultcurrency} && ($form->{currency} ne $form->{defaultcurrency})) { if ($form->{forex}) { $exchangerate .= qq| - | . $locale->text('Exchangerate') . qq| - {exchangerate}>$form->{exchangerate} + | . $locale->text('Exchangerate') . qq| + {exchangerate}>$form->{exchangerate} |; } else { $exchangerate .= qq| @@ -364,10 +293,10 @@ sub form_header { } $taxincluded = qq| - - {taxincluded}> - | . $locale->text('Tax Included') . qq| - + + {taxincluded}> + | . $locale->text('Tax Included') . qq| + |; if (($rows = $form->numtextrows($form->{notes}, 50)) < 2) { @@ -377,21 +306,18 @@ sub form_header { qq|$form->{notes}|; $department = qq| - - | . $locale->text('Department') . qq| - $form->{selectdepartment} - - - + + | . $locale->text('Department') . qq| + $form->{selectdepartment} + + + | if $form->{selectdepartment}; - $n = ($form->{creditremaining} =~ /-/) ? "0" : "1"; + my $n = ($form->{creditremaining} =~ /-/) ? "0" : "1"; - $customer = - ($form->{selectcustomer}) - ? qq|$form->{ -selectcustomer}| + $customer = ($form->{selectcustomer}) + ? qq|$form->{selectcustomer}| : qq||; $employee = qq| @@ -400,11 +326,11 @@ selectcustomer}| if ($form->{selectemployee}) { $employee = qq| - - | . $locale->text('Salesperson') . qq| - $form->{selectemployee} - - + + | . $locale->text('Salesperson') . qq| + $form->{selectemployee} + + |; } @@ -412,12 +338,13 @@ selectcustomer}| map({ push(@old_project_ids, $form->{"project_id_$_"}) if ($form->{"project_id_$_"}); } (1..$form->{"rowcount"})); - $form->get_lists("projects" => { "key" => "ALL_PROJECTS", - "all" => 0, - "old_id" => \@old_project_ids }, - "charts" => { "key" => "ALL_CHARTS", - "transdate" => $form->{transdate} }, - "taxcharts" => "ALL_TAXCHARTS"); + $form->get_lists("projects" => { "key" => "ALL_PROJECTS", + "all" => 0, + "old_id" => \@old_project_ids }, + "charts" => { "key" => "ALL_CHARTS", + "transdate" => $form->{transdate} }, + "taxcharts" => { "key" => "ALL_TAXCHARTS", + "module" => "AR" },); map({ $_->{link_split} = [ split(/:/, $_->{link}) ]; } @{ $form->{ALL_CHARTS} }); @@ -500,9 +427,20 @@ selectcustomer}| qq||; } + my $follow_up_vc = $form->{customer}; + $follow_up_vc =~ s/--.*?//; + my $follow_up_trans_info = "$form->{invnumber} ($follow_up_vc)"; + $form->{javascript} .= qq|| . - qq||; + qq|| . + qq||; + + my $globalprojectnumber = + NTI($cgi->popup_menu('-name' => "globalproject_id", + '-values' => \@project_values, + '-labels' => \%project_labels, + '-default' => $form->{"globalproject_id"} )); $form->header; $onload = qq|focus()|; @@ -518,6 +456,10 @@ selectcustomer}| {closedto}> {locked}> + + + + | . ($form->{saved_message} ? qq|$form->{saved_message}| : "") . qq| @@ -530,66 +472,70 @@ selectcustomer}| - - - - | . $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| - $form->{selectcurrency} - - {defaultcurrency}> - {fxgain_accno}> - {fxloss_accno}> - $exchangerate - - $department - $taxincluded - - - - - $employee - - | . $locale->text('Invoice Number') . qq| - - - - | . $locale->text('Order Number') . qq| - - - - | . $locale->text('Invoice Date') . qq| + + + + | . $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| + $form->{selectcurrency} + + {defaultcurrency}> + {fxgain_accno}> + {fxloss_accno}> + $exchangerate + + $department + $taxincluded + + + + + $employee + + | . $locale->text('Invoice Number') . qq| + + + + | . $locale->text('Order Number') . qq| + + + + | . $locale->text('Invoice Date') . qq| $button1 - - - | . $locale->text('Due Date') . qq| + + + | . $locale->text('Due Date') . qq| $button2 - + + + | . $locale->text('Project Number') . qq| + $globalprojectnumber + - - + + @@ -599,26 +545,24 @@ $jsscript - - | + + | . $locale->text('Account') . qq| - | + | . $locale->text('Amount') . qq| | . $locale->text('Tax') . qq| | - . $locale->text('Korrektur') . qq| - | . $locale->text('Taxkey') . qq| | . $locale->text('Project') . qq| - + |; $amount = $locale->text('Amount'); $project = $locale->text('Project'); - for $i (1 .. $form->{rowcount}) { + for my $i (1 .. $form->{rowcount}) { # format amounts $form->{"amount_$i"} = @@ -641,7 +585,13 @@ $jsscript $selected_taxchart = "$item->{id}--$item->{rate}"; } - $selected_taxchart = $taxchart_init unless ($form->{"taxchart_$i"}); + if (!$form->{"taxchart_$i"}) { + if ($form->{"AR_amount_$i"} =~ m/.--./) { + $selected_taxchart = join '--', map { ($_->{id}, $_->{rate}) } first { $_->{id} == $item->{tax_id} } @{ $form->{ALL_TAXCHARTS} }; + } else { + $selected_taxchart = $taxchart_init; + } + } $selectAR_amount = NTI($cgi->popup_menu('-name' => "AR_amount_$i", @@ -663,8 +613,6 @@ $jsscript '-default' => $selected_taxchart)) . qq||; - $korrektur_checked = ($form->{"korrektur_$i"} ? 'checked' : ''); - my $projectnumber = NTI($cgi->popup_menu('-name' => "project_id_$i", '-values' => \@project_values, @@ -672,19 +620,19 @@ $jsscript '-default' => $form->{"project_id_$i"} )); print qq| - + $selectAR_amount {"amount_$i"}> - {"tax_$i"}> - + $form->{"tax_$i"} $tax $projectnumber - + |; $amount = ""; $project = ""; } + $form->{invtotal_unformatted} = $form->{invtotal}; $form->{invtotal} = $form->format_amount(\%myconfig, $form->{invtotal}, 2); $ARselected = @@ -700,15 +648,15 @@ $jsscript - ${ARselected} - $form->{invtotal} + ${ARselected} + $form->{invtotal} - {oldinvtotal}> - {oldtotalpaid}> + {oldinvtotal}> + {oldtotalpaid}> - + - + @@ -719,22 +667,22 @@ $jsscript - | . $locale->text('Notes') . qq| - $notes - + | . $locale->text('Notes') . qq| + $notes + - - | + + | . $locale->text('Incoming Payments') . qq| - + |; - if ($form->{currency} eq $form->{defaultcurrency}) { + if ($form->{defaultcurrency} && ($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); @@ -745,8 +693,8 @@ $jsscript $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') . ""; + $column_data{memo} = "" . $locale->text('Memo') . ""; + $column_data{paid_project_id} = "" . $locale->text('Project Number') . ""; print " @@ -756,9 +704,11 @@ $jsscript "; - my @triggers = (); + my @triggers = (); + $form->{totalpaid} = 0; + $form->{paidaccounts}++ if ($form->{"paid_$form->{paidaccounts}"}); - for $i (1 .. $form->{paidaccounts}) { + for my $i (1 .. $form->{paidaccounts}) { print " "; @@ -770,22 +720,45 @@ $jsscript '-labels' => \%AR_paid_labels, '-default' => $form->{"AR_paid_$i"})); + $form->{totalpaid} += $form->{"paid_$i"}; + # 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"}); + if ($form->{"exchangerate_$i"} == 0) { + $form->{"exchangerate_$i"} = ""; + } else { + $form->{"exchangerate_$i"} = + $form->format_amount(\%myconfig, $form->{"exchangerate_$i"}); + } + + print qq|{"acc_trans_id_$i"}>\n|; + print qq|{"gldate_$i"}>\n|; + my $changeable = 1; + if ($::lx_office_conf{features}->{payments_changeable} == 0) { + # never + $changeable = ($form->{"acc_trans_id_$i"})? 0 : 1; + } + if ($::lx_office_conf{features}->{payments_changeable} == 2) { + # on the same day + $changeable = (($form->{"gldate_$i"} eq '') || $form->current_date(\%myconfig) eq $form->{"gldate_$i"}); + } $exchangerate = qq| |; - if ($form->{currency} ne $form->{defaultcurrency}) { + if ($form->{defaultcurrency} && ($form->{currency} ne $form->{defaultcurrency})) { if ($form->{"forex_$i"}) { $exchangerate = qq|{"exchangerate_$i"}>$form->{"exchangerate_$i"}|; } else { - $exchangerate = - qq|{"exchangerate_$i"}>|; + if ($changeable) { + $exchangerate = + qq|{"exchangerate_$i"}>|; + } else { + $exchangerate = + qq|{"exchangerate_$i"}>$form->{"exchangerate_$i"}|; + } } } @@ -793,36 +766,96 @@ $jsscript {"forex_$i"}> |; - $column_data{paid} = - qq||; - $column_data{AR_paid} = - qq|${selectAR_paid}|; - $column_data{exchangerate} = qq|$exchangerate|; - $column_data{datepaid} = - qq| + my $datepaid; + if ($changeable) { + $datepaid = qq| |; - $column_data{source} = - qq||; - $column_data{memo} = - qq||; + } else { + $datepaid = qq|$form->{"datepaid_$i"}|. + qq|{"datepaid_$i"}>|; + } + + my $paid; + if ($changeable) { + $paid = qq||; + } else { + $paid = qq|$form->{"paid_$i"}|. + qq|{"paid_$i"}>|; + } - $column_data{paid_project_id} = + my $source; + if ($changeable) { + $source = qq||; + } else { + $source = qq|$form->{"source_$i"}|. + qq|{"source_$i"}>|; + } + + my $memo; + if ($changeable) { + $memo = qq||; + } else { + $memo = qq|$form->{"memo_$i"}|. + qq|{"memo_$i"}>|; + } + + my $AR_paid; + if ($changeable) { + $AR_paid = qq|${selectAR_paid}|; + } else { + $AR_paid = qq|$form->{"AR_paid_$i"}|. + qq|{"AR_paid_$i"}>|; + } + + my $paid_project_id; + if ($changeable) { + $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||; + } else { + my $projectnumber = $project_labels{$form->{"paid_project_id_$i"}}; + $paid_project_id = qq|$projectnumber|. + qq|{"paid_project_id_$i"}>|; + } + + $column_data{paid} = $paid; + $column_data{AR_paid} = $AR_paid; + $column_data{exchangerate} = qq|$exchangerate|; + $column_data{datepaid} = $datepaid; + $column_data{source} = $source; + $column_data{memo} = $memo; + $column_data{paid_project_id} = $paid_project_id; map { print qq|$column_data{$_}\n| } @column_index; print " "; - push(@triggers, "datepaid_$i", "BL", "trigger_datepaid_$i"); + if ($changeable) { + push(@triggers, "datepaid_$i", "BL", "trigger_datepaid_$i"); + } } - print $form->write_trigger(\%myconfig, scalar(@triggers) / 3, @triggers) . + my $paid_missing = $form->{invtotal_unformatted} - $form->{totalpaid}; + + print qq| + + + + | . $locale->text('Total') . qq| + | . H($form->format_amount(\%myconfig, $form->{totalpaid}, 2)) . qq| + + + + + | . $locale->text('Missing amount') . qq| + | . H($form->format_amount(\%myconfig, $paid_missing, 2)) . qq| + +| . $form->write_trigger(\%myconfig, scalar(@triggers) / 3, @triggers) . qq| {paidaccounts}> @@ -835,20 +868,38 @@ $jsscript |; - $lxdebug->leave_sub(); + $main::lxdebug->leave_sub(); } sub form_footer { - $lxdebug->enter_sub(); + $main::lxdebug->enter_sub(); + + $main::auth->assert('general_ledger'); + + my $form = $main::form; + my %myconfig = %main::myconfig; + my $locale = $main::locale; + my $cgi = $::request->{cgi}; + + my ($transdate, $closedto); + + my $follow_ups_block; + if ($form->{id}) { + my $follow_ups = FU->follow_ups('trans_id' => $form->{id}); + + if (@{ $follow_ups} ) { + my $num_due = sum map { $_->{due} * 1 } @{ $follow_ups }; + $follow_ups_block = qq|| . $locale->text("There are #1 unfinished follow-ups of which #2 are due.", scalar @{ $follow_ups }, $num_due) . qq||; + } + } print qq| +$follow_ups_block + - -{login}> -{password}> | . $cgi->hidden('-name' => 'draft_id', '-default' => [$form->{draft_id}]) . $cgi->hidden('-name' => 'draft_description', '-default' => [$form->{draft_description}]) @@ -869,11 +920,12 @@ sub form_footer { $transdate = $form->datetonum($form->{transdate}, \%myconfig); $closedto = $form->datetonum($form->{closedto}, \%myconfig); - # ToDO: insert a global check for stornos, so that a storno is only possible a limited time after saving it - print qq|| - if ($form->{id} && !IS->has_storno(\%myconfig, $form, 'ar') && !IS->is_storno(\%myconfig, $form, 'ar')); - print qq|\n|; + + # ToDO: - insert a global check for stornos, so that a storno is only possible a limited time after saving it + print qq| | + if ($form->{id} && !IS->has_storno(\%myconfig, $form, 'ar') && !IS->is_storno(\%myconfig, $form, 'ar') && (($form->{totalpaid} == 0) || ($form->{totalpaid} eq ""))); + if ($form->{id}) { if ($form->{radier}) { print qq| @@ -885,11 +937,14 @@ sub form_footer { |; } print qq| - |; + + |; } else { if ($transdate > $closedto) { - print qq| | . + print qq| | . NTI($cgi->submit('-name' => 'action', '-value' => $locale->text('Save draft'), '-class' => 'submit')); } } @@ -900,9 +955,16 @@ sub form_footer { } # button for saving history if($form->{id} ne "") { - print qq|{id}); name=history id=history value=| . $locale->text('history') . qq|>|; + print qq| {id}); name=history id=history value=| . $locale->text('history') . qq|> |; } # /button for saving history + # mark_as_paid button + if($form->{id} ne "") { + print qq||; + } + # /mark_as_paid button + print " @@ -910,41 +972,60 @@ sub form_footer {
$form->{saved_message}
| . $locale->text("There are #1 unfinished follow-ups of which #2 are due.", scalar @{ $follow_ups }, $num_due) . qq|