X-Git-Url: http://wagnertech.de/git?a=blobdiff_plain;ds=inline;f=bin%2Fmozilla%2Far.pl;h=a740728ac406b2560aca95d1ea3c87c1b83286fd;hb=19db5b9099df8a70daac82388e45c0aee17c9266;hp=8a01c195902e21265897b2c70d622632de5355d3;hpb=d5c1e4fa391f26fc0acd568729a98493edf319d8;p=kivitendo-erp.git diff --git a/bin/mozilla/ar.pl b/bin/mozilla/ar.pl index 8a01c1959..a740728ac 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, @curr); $form->create_links("AR", \%myconfig, "customer"); $duedate = $form->{duedate}; @@ -148,151 +173,60 @@ sub create_links { map { $form->{selectcurrency} .= "$_\n" } @curr; # 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 = $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"); @@ -331,16 +265,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} = @@ -352,8 +293,8 @@ sub form_header { if ($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 +305,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 +318,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 +338,11 @@ selectcustomer}| if ($form->{selectemployee}) { $employee = qq| - - | . $locale->text('Salesperson') . qq| - $form->{selectemployee} - - + + | . $locale->text('Salesperson') . qq| + $form->{selectemployee} + + |; } @@ -412,12 +350,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 +439,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()|; @@ -518,6 +462,10 @@ selectcustomer}| {closedto}> {locked}> + + + + | . ($form->{saved_message} ? qq|$form->{saved_message}| : "") . qq| @@ -530,66 +478,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 - + - - + + @@ -599,26 +547,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 +587,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 +615,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 +622,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 +650,15 @@ $jsscript - ${ARselected} - $form->{invtotal} + ${ARselected} + $form->{invtotal} - {oldinvtotal}> - {oldtotalpaid}> + {oldinvtotal}> + {oldtotalpaid}> - + - + @@ -719,19 +669,19 @@ $jsscript - | . $locale->text('Notes') . qq| - $notes - + | . $locale->text('Notes') . qq| + $notes + - - | + + | . $locale->text('Incoming Payments') . qq| - + |; if ($form->{currency} eq $form->{defaultcurrency}) { @@ -745,8 +695,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 +706,11 @@ $jsscript "; - my @triggers = (); + my @triggers = (); + my $totalpaid = 0; + $form->{paidaccounts}++ if ($form->{"paid_$form->{paidaccounts}"}); - for $i (1 .. $form->{paidaccounts}) { + for my $i (1 .. $form->{paidaccounts}) { print " "; @@ -770,6 +722,8 @@ $jsscript '-labels' => \%AR_paid_labels, '-default' => $form->{"AR_paid_$i"})); + $totalpaid += $form->{"paid_$i"}; + # format amounts if ($form->{"paid_$i"}) { $form->{"paid_$i"} = @@ -778,6 +732,10 @@ $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->{"forex_$i"}) { @@ -822,7 +780,22 @@ $jsscript push(@triggers, "datepaid_$i", "BL", "trigger_datepaid_$i"); } - print $form->write_trigger(\%myconfig, scalar(@triggers) / 3, @triggers) . + my $paid_missing = $form->{invtotal_unformatted} - $totalpaid; + + print qq| + + + + | . $locale->text('Total') . qq| + | . H($form->format_amount(\%myconfig, $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 +808,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}]) @@ -869,11 +860,12 @@ sub form_footer { $transdate = $form->datetonum($form->{transdate}, \%myconfig); $closedto = $form->datetonum($form->{closedto}, \%myconfig); + 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 ""))); - print qq|\n|; if ($form->{id}) { if ($form->{radier}) { print qq| @@ -885,11 +877,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 +895,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 +912,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|