X-Git-Url: http://wagnertech.de/git?a=blobdiff_plain;f=bin%2Fmozilla%2Far.pl;h=3d4fe26649274218c5fc0d053ee13fa96def30d7;hb=1e0d413084100ccd892e8c5be95703be5d965de7;hp=11a12e440dbc75f9a594d3ab07fc406c323bbe53;hpb=3505ff1bb654d331bd384461d471fa895635e7b4;p=kivitendo-erp.git diff --git a/bin/mozilla/ar.pl b/bin/mozilla/ar.pl index 11a12e440..3d4fe2664 100644 --- a/bin/mozilla/ar.pl +++ b/bin/mozilla/ar.pl @@ -32,26 +32,21 @@ #====================================================================== use POSIX qw(strftime); +use List::Util qw(sum first); use SL::AR; +use SL::FU; use SL::IS; use SL::PE; use SL::ReportGenerator; -# use strict; -#use warnings; - -# imports -our ($cgi, $form, $lxdebug, $locale, %myconfig); - 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') @@ -82,33 +77,41 @@ require "bin/mozilla/reportgenerator.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 @@ -118,22 +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(); - my ($duedate, $taxincluded, @curr); + $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}; @@ -152,37 +164,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 @@ -194,16 +204,23 @@ 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, $korrektur_checked, $ARselected, $tax); + my ($selectAR_amount, $selectAR_paid, $ARselected, $tax); my (@column_index, %column_data); @@ -250,35 +267,22 @@ sub form_header { s/option>\Q$form->{$item}\E/option selected>$form->{$item}/; } - $form->{exchangerate} = $exchangerate - if ( - $form->{forex} = ( - $exchangerate = - $form->check_exchangerate( - \%myconfig, $form->{currency}, $form->{transdate}, 'buy' - ))); + $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} = - $form->format_amount(\%myconfig, $form->{creditremaining}, 0, "0"); + $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| @@ -289,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) { @@ -302,18 +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}; my $n = ($form->{creditremaining} =~ /-/) ? "0" : "1"; - $customer = ($form->{selectcustomer}) - ? qq|$form->{selectcustomer}| + $customer = ($form->{selectcustomer}) + ? qq|$form->{selectcustomer}| : qq||; $employee = qq| @@ -322,11 +326,11 @@ sub form_header { if ($form->{selectemployee}) { $employee = qq| - - | . $locale->text('Salesperson') . qq| - $form->{selectemployee} - - + + | . $locale->text('Salesperson') . qq| + $form->{selectemployee} + + |; } @@ -334,12 +338,13 @@ sub form_header { 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} }); @@ -422,9 +427,14 @@ sub form_header { 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()|; @@ -440,6 +450,10 @@ sub form_header { {closedto}> {locked}> + + + + | . ($form->{saved_message} ? qq|$form->{saved_message}| : "") . qq| @@ -452,66 +466,66 @@ sub form_header { - - - - | . $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 - + - - + + @@ -521,20 +535,18 @@ $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'); @@ -563,7 +575,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", @@ -585,8 +603,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, @@ -594,14 +610,13 @@ $jsscript '-default' => $form->{"project_id_$i"} )); print qq| - + $selectAR_amount {"amount_$i"}> - {"tax_$i"}> - + $form->{"tax_$i"} $tax $projectnumber - + |; $amount = ""; $project = ""; @@ -623,15 +638,15 @@ $jsscript - ${ARselected} - $form->{invtotal} + ${ARselected} + $form->{invtotal} - {oldinvtotal}> - {oldtotalpaid}> + {oldinvtotal}> + {oldtotalpaid}> - + - + @@ -642,22 +657,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); @@ -668,8 +683,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 " @@ -680,7 +695,7 @@ $jsscript "; my @triggers = (); - my $totalpaid = 0; + $form->{totalpaid} = 0; $form->{paidaccounts}++ if ($form->{"paid_$form->{paidaccounts}"}); for my $i (1 .. $form->{paidaccounts}) { @@ -695,7 +710,7 @@ $jsscript '-labels' => \%AR_paid_labels, '-default' => $form->{"AR_paid_$i"})); - $totalpaid += $form->{"paid_$i"}; + $form->{totalpaid} += $form->{"paid_$i"}; # format amounts if ($form->{"paid_$i"}) { @@ -710,7 +725,7 @@ $jsscript } $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"}|; @@ -753,14 +768,14 @@ $jsscript push(@triggers, "datepaid_$i", "BL", "trigger_datepaid_$i"); } - my $paid_missing = $form->{invtotal_unformatted} - $totalpaid; + my $paid_missing = $form->{invtotal_unformatted} - $form->{totalpaid}; print qq| | . $locale->text('Total') . qq| - | . H($form->format_amount(\%myconfig, $totalpaid, 2)) . qq| + | . H($form->format_amount(\%myconfig, $form->{totalpaid}, 2)) . qq| @@ -781,22 +796,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}]) @@ -821,7 +852,7 @@ sub form_footer { # 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')); + 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}) { @@ -834,7 +865,10 @@ sub form_footer { |; } print qq| - |; + + |; } else { if ($transdate > $closedto) { @@ -852,9 +886,9 @@ sub form_footer { 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 @@ -866,24 +900,38 @@ 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|