X-Git-Url: http://wagnertech.de/git?a=blobdiff_plain;f=bin%2Fmozilla%2Far.pl;h=f03a74b7db99e31804a02c9b305b06f4fa12fad2;hb=dbd0ae115bd9a6ba0ede24f9655a29df6bf7dc3b;hp=ad682ee6355475d86096a48cff0853eeb84b9158;hpb=a4518c4ddcf1aa4e77df38b39ae45fb0b54e3a7d;p=kivitendo-erp.git diff --git a/bin/mozilla/ar.pl b/bin/mozilla/ar.pl index ad682ee63..f03a74b7d 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') @@ -72,34 +76,44 @@ require "bin/mozilla/drafts.pl"; # $locale->text('Nov') # $locale->text('Dec') +my $totalpaid; + sub add { - $lxdebug->enter_sub(); + $main::lxdebug->enter_sub(); + + $main::auth->assert('general_ledger'); - return $lxdebug->leave_sub() if (load_draft_maybe()); + 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($form->dbconnect(\%myconfig)); } - # /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" 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 +123,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,37 +166,35 @@ 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 @@ -183,11 +206,25 @@ sub create_links { ($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 = $main::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"); @@ -226,16 +263,23 @@ 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}/; } + $form->{forex} = $form->check_exchangerate( \%myconfig, $form->{currency}, $form->{transdate}, 'buy'); + $form->{exchangerate} = $form->{forex} if $form->{forex}; + # format amounts $form->{exchangerate} = $form->format_amount(\%myconfig, $form->{exchangerate}); + if ($form->{exchangerate} == 0) { + $form->{exchangerate} = ""; + } + $form->{creditlimit} = $form->format_amount(\%myconfig, $form->{creditlimit}, 0, "0"); $form->{creditremaining} = @@ -244,11 +288,11 @@ sub form_header { $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| @@ -259,10 +303,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) { @@ -272,21 +316,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| @@ -295,11 +336,11 @@ selectcustomer}| if ($form->{selectemployee}) { $employee = qq| - - | . $locale->text('Salesperson') . qq| - $form->{selectemployee} - - + + | . $locale->text('Salesperson') . qq| + $form->{selectemployee} + + |; } @@ -307,12 +348,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} }); @@ -395,9 +437,14 @@ 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||; $form->header; $onload = qq|focus()|; @@ -413,6 +460,10 @@ selectcustomer}| {closedto}> {locked}> + + + + | . ($form->{saved_message} ? qq|$form->{saved_message}| : "") . qq| @@ -425,66 +476,66 @@ 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 - + - - + + @@ -494,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"} = @@ -536,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", @@ -558,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, @@ -567,14 +620,13 @@ $jsscript '-default' => $form->{"project_id_$i"} )); print qq| - + $selectAR_amount {"amount_$i"}> - {"tax_$i"}> - + $form->{"tax_$i"} $tax $projectnumber - + |; $amount = ""; $project = ""; @@ -596,15 +648,15 @@ $jsscript - ${ARselected} - $form->{invtotal} + ${ARselected} + $form->{invtotal} - {oldinvtotal}> - {oldtotalpaid}> + {oldinvtotal}> + {oldtotalpaid}> - + - + @@ -615,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); @@ -641,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 " @@ -656,7 +708,7 @@ $jsscript my $totalpaid = 0; $form->{paidaccounts}++ if ($form->{"paid_$form->{paidaccounts}"}); - for $i (1 .. $form->{paidaccounts}) { + for my $i (1 .. $form->{paidaccounts}) { print " "; @@ -678,8 +730,12 @@ $jsscript $form->{"exchangerate_$i"} = $form->format_amount(\%myconfig, $form->{"exchangerate_$i"}); + if ($form->{"exchangerate_$i"} == 0) { + $form->{"exchangerate_$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"}|; @@ -750,20 +806,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 = $main::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}]) @@ -787,8 +861,8 @@ sub form_footer { 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->{paid_1}); + print qq| | + if ($form->{id} && !IS->has_storno(\%myconfig, $form, 'ar') && !IS->is_storno(\%myconfig, $form, 'ar') && (($totalpaid == 0) || ($totalpaid eq ""))); if ($form->{id}) { if ($form->{radier}) { @@ -801,11 +875,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')); } } @@ -816,12 +893,12 @@ 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 @@ -833,47 +910,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|