X-Git-Url: http://wagnertech.de/git?a=blobdiff_plain;f=bin%2Fmozilla%2Far.pl;h=88a9b97bf74e3fd24ee40754b3612e8068286e13;hb=eeb07c164e0c3398f14372308b404fb07e2102cf;hp=fe7b0e91efec73338bffebdec6ab176348964b1f;hpb=971c972736d11eb59b1494ceff097a4a9c1f1730;p=kivitendo-erp.git diff --git a/bin/mozilla/ar.pl b/bin/mozilla/ar.pl index fe7b0e91e..88a9b97bf 100644 --- a/bin/mozilla/ar.pl +++ b/bin/mozilla/ar.pl @@ -32,16 +32,24 @@ #====================================================================== use POSIX qw(strftime); +use List::Util qw(sum); 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/report_generator.pl"; +require "bin/mozilla/reportgenerator.pl"; 1; @@ -78,6 +86,8 @@ require "bin/mozilla/report_generator.pl"; sub add { $lxdebug->enter_sub(); + $auth->assert('general_ledger'); + return $lxdebug->leave_sub() if (load_draft_maybe()); # saving the history @@ -89,9 +99,7 @@ sub add { # /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}; @@ -103,6 +111,9 @@ sub add { sub edit { $lxdebug->enter_sub(); + + $auth->assert('general_ledger'); + # show history button $form->{javascript} = qq||; #/show hhistory button @@ -118,6 +129,8 @@ sub edit { sub display_form { $lxdebug->enter_sub(); + $auth->assert('general_ledger'); + &form_header; &form_footer; @@ -127,6 +140,10 @@ sub display_form { sub create_links { $lxdebug->enter_sub(); + $auth->assert('general_ledger'); + + my ($duedate, $taxincluded, @curr); + $form->create_links("AR", \%myconfig, "customer"); $duedate = $form->{duedate}; @@ -192,6 +209,15 @@ sub create_links { sub form_header { $lxdebug->enter_sub(); + $auth->assert('general_ledger'); + + 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 (@column_index, %column_data); + + $title = $form->{title}; $form->{title} = $locale->text("$title Accounts Receivables Transaction"); @@ -229,7 +255,7 @@ 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}/; @@ -295,13 +321,10 @@ sub form_header { | if $form->{selectdepartment}; - $n = ($form->{creditremaining} =~ /-/) ? "0" : "1"; + my $n = ($form->{creditremaining} =~ /-/) ? "0" : "1"; - $customer = - ($form->{selectcustomer}) - ? qq|| + $customer = ($form->{selectcustomer}) + ? qq|| : qq||; $employee = qq| @@ -410,9 +433,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()|; @@ -428,6 +456,10 @@ selectcustomer}| {closedto}> {locked}> + + + + | . ($form->{saved_message} ? qq|

$form->{saved_message}

| : "") . qq| @@ -528,7 +560,7 @@ $jsscript $amount = $locale->text('Amount'); $project = $locale->text('Project'); - for $i (1 .. $form->{rowcount}) { + for my $i (1 .. $form->{rowcount}) { # format amounts $form->{"amount_$i"} = @@ -671,7 +703,7 @@ $jsscript my $totalpaid = 0; $form->{paidaccounts}++ if ($form->{"paid_$form->{paidaccounts}"}); - for $i (1 .. $form->{paidaccounts}) { + for my $i (1 .. $form->{paidaccounts}) { print " "; @@ -775,14 +807,27 @@ $jsscript sub form_footer { $lxdebug->enter_sub(); + $auth->assert('general_ledger'); + + 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}]) @@ -806,8 +851,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')); if ($form->{id}) { if ($form->{radier}) { @@ -820,11 +865,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')); } } @@ -835,7 +883,7 @@ 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 @@ -857,33 +905,40 @@ sub form_footer { sub mark_as_paid { $lxdebug->enter_sub(); + + $auth->assert('general_ledger'); + &mark_as_paid_common(\%myconfig,"ar"); + $lxdebug->leave_sub(); } sub update { $lxdebug->enter_sub(); + $auth->assert('general_ledger'); + my $display = shift; + my ($totaltax, $exchangerate, $totalpaid); + $form->{invtotal} = 0; map { $form->{$_} = $form->parse_amount(\%myconfig, $form->{$_}) } qw(exchangerate creditlimit creditremaining); - @flds = qw(amount AR_amount projectnumber oldprojectnumber project_id); - $count = 0; - @a = (); + my @flds = qw(amount AR_amount projectnumber oldprojectnumber project_id); + my $count = 0; + my @a = (); - for $i (1 .. $form->{rowcount}) { - $form->{"amount_$i"} = - $form->parse_amount(\%myconfig, $form->{"amount_$i"}); + for my $i (1 .. $form->{rowcount}) { + $form->{"amount_$i"} = $form->parse_amount(\%myconfig, $form->{"amount_$i"}); $form->{"tax_$i"} = $form->parse_amount(\%myconfig, $form->{"tax_$i"}); if ($form->{"amount_$i"}) { push @a, {}; - $j = $#a; + my $j = $#a; if (!$form->{"korrektur_$i"}) { - ($taxkey, $rate) = split(/--/, $form->{"taxchart_$i"}); + my ($taxkey, $rate) = split(/--/, $form->{"taxchart_$i"}); if ($taxkey > 1) { if ($form->{taxincluded}) { $form->{"tax_$i"} = $form->{"amount_$i"} / ($rate + 1) * $rate; @@ -915,14 +970,14 @@ sub update { ))); $form->{invdate} = $form->{transdate}; - $save_AR = $form->{AR}; - &check_name(customer); + my $save_AR = $form->{AR}; + check_name("customer"); $form->{AR} = $save_AR; $form->{invtotal} = ($form->{taxincluded}) ? $form->{invtotal} : $form->{invtotal} + $totaltax; - for $i (1 .. $form->{paidaccounts}) { + for my $i (1 .. $form->{paidaccounts}) { if ($form->parse_amount(\%myconfig, $form->{"paid_$i"})) { map { $form->{"${_}_$i"} = @@ -952,49 +1007,64 @@ sub update { $lxdebug->leave_sub(); } +# +# ToDO: fix $closedto and $invdate +# sub post_payment { $lxdebug->enter_sub(); + $auth->assert('general_ledger'); + $form->{defaultcurrency} = $form->get_default_currency(\%myconfig); - for $i (1 .. $form->{paidaccounts}) { + for my $i (1 .. $form->{paidaccounts}) { + if ($form->parse_amount(\%myconfig, $form->{"paid_$i"})) { - $datepaid = $form->datetonum($form->{"datepaid_$i"}, \%myconfig); + my $datepaid = $form->datetonum($form->{"datepaid_$i"}, \%myconfig); $form->isblank("datepaid_$i", $locale->text('Payment date missing!')); - $form->error($locale->text('Cannot post payment for a closed period!')) - if ($datepaid <= $closedto); +# $form->error($locale->text('Cannot post payment for a closed period!')) if ($datepaid <= $closedto); if ($form->{currency} ne $form->{defaultcurrency}) { - $form->{"exchangerate_$i"} = $form->{exchangerate} - if ($invdate == $datepaid); - $form->isblank("exchangerate_$i", - $locale->text('Exchangerate for payment missing!')); +# $form->{"exchangerate_$i"} = $form->{exchangerate} if ($invdate == $datepaid); + $form->isblank("exchangerate_$i", $locale->text('Exchangerate for payment missing!')); } } } ($form->{AR}) = split /--/, $form->{AR}; ($form->{AR_paid}) = split /--/, $form->{AR_paid}; - $form->redirect($locale->text('Payment posted!')) - if (AR->post_payment(\%myconfig, \%$form)); - $form->error($locale->text('Cannot post payment!')); - + $form->redirect($locale->text('Payment posted!')) if (AR->post_payment(\%myconfig, \%$form)); + $form->error($locale->text('Cannot post payment!')); $lxdebug->leave_sub(); } +sub _post { + + $auth->assert('general_ledger'); + + # inline post + post(1); +} + sub post { $lxdebug->enter_sub(); + $auth->assert('general_ledger'); + + my ($inline) = @_; + + my ($datepaid); + # check if there is an invoice number, invoice and due date $form->isblank("transdate", $locale->text('Invoice Date missing!')); $form->isblank("duedate", $locale->text('Due Date missing!')); $form->isblank("customer", $locale->text('Customer missing!')); - $closedto = $form->datetonum($form->{closedto}, \%myconfig); - $transdate = $form->datetonum($form->{transdate}, \%myconfig); + my $closedto = $form->datetonum($form->{closedto}, \%myconfig); + my $transdate = $form->datetonum($form->{transdate}, \%myconfig); $form->error($locale->text('Cannot post transaction for a closed period!')) if ($transdate <= $closedto); $form->error($locale->text('Zero amount posting!')) @@ -1005,7 +1075,7 @@ sub post { delete($form->{AR}); - for $i (1 .. $form->{paidaccounts}) { + for my $i (1 .. $form->{paidaccounts}) { if ($form->parse_amount(\%myconfig, $form->{"paid_$i"})) { $datepaid = $form->datetonum($form->{"datepaid_$i"}, \%myconfig); @@ -1022,30 +1092,29 @@ sub post { } # if oldcustomer ne customer redo form - ($customer) = split /--/, $form->{customer}; + my ($customer) = split /--/, $form->{customer}; if ($form->{oldcustomer} ne "$customer--$form->{customer_id}") { - &update; + update(); exit; } $form->{AR}{receivables} = $form->{ARselected}; $form->{storno} = 0; + $lxdebug->message(0, $form->{amount}); $form->{id} = 0 if $form->{postasnew}; + $form->error($locale->text('Cannot post transaction!')) unless AR->post_transaction(\%myconfig, \%$form); - - if (AR->post_transaction(\%myconfig, \%$form)) { - # saving the history - if(!exists $form->{addition} && $form->{id} ne "") { - $form->{snumbers} = "invnumber_$form->{invnumber}"; - $form->{addition} = "POSTED"; - $form->save_history($form->dbconnect(\%myconfig)); - } - # /saving the history - remove_draft() if $form->{remove_draft}; - $form->redirect($locale->text('Transaction posted!')); + # saving the history + if(!exists $form->{addition} && $form->{id} ne "") { + $form->{snumbers} = "invnumber_$form->{invnumber}"; + $form->{addition} = "POSTED"; + $form->save_history($form->dbconnect(\%myconfig)); } - $form->error($locale->text('Cannot post transaction!')); + # /saving the history + remove_draft() if $form->{remove_draft}; + + $form->redirect($locale->text('Transaction posted!')) unless $inline; $lxdebug->leave_sub(); } @@ -1053,6 +1122,8 @@ sub post { sub post_as_new { $lxdebug->enter_sub(); + $auth->assert('general_ledger'); + $form->{postasnew} = 1; # saving the history if(!exists $form->{addition} && $form->{id} ne "") { @@ -1069,6 +1140,8 @@ sub post_as_new { sub use_as_template { $lxdebug->enter_sub(); + $auth->assert('general_ledger'); + map { delete $form->{$_} } qw(printed emailed queued invnumber invdate deliverydate id datepaid_1 source_1 memo_1 paid_1 exchangerate_1 AP_paid_1 storno); $form->{paidaccounts} = 1; $form->{rowcount}--; @@ -1081,6 +1154,8 @@ sub use_as_template { sub delete { $lxdebug->enter_sub(); + $auth->assert('general_ledger'); + $form->{title} = $locale->text('Confirm!'); $form->header; @@ -1093,7 +1168,8 @@ sub delete {
{script}> |; - foreach $key (keys %$form) { + foreach my $key (keys %$form) { + next if (($key eq 'login') || ($key eq 'password') || ('' ne ref $form->{$key})); $form->{$key} =~ s/\"/"/g; print qq|\n|; } @@ -1118,7 +1194,10 @@ sub delete { sub yes { $lxdebug->enter_sub(); - if (AR->delete_transaction(\%myconfig, \%$form, $spool)) { + + $auth->assert('general_ledger'); + + if (AR->delete_transaction(\%myconfig, \%$form)) { # saving the history if(!exists $form->{addition}) { $form->{snumbers} = qq|invnumber_| . $form->{invnumber}; @@ -1136,6 +1215,11 @@ sub yes { sub search { $lxdebug->enter_sub(); + $auth->assert('general_ledger | invoice_edit'); + + my ($customer, $department); + my ($jsscript, $button1, $button2, $onload); + # setup customer selection $form->all_vc(\%myconfig, "customer", "AR"); @@ -1315,6 +1399,12 @@ sub search { | . $locale->text('Ship via') . qq| + + | + . $locale->text('Ertrag') . qq| + | + . $locale->text('Ertrag prozentual') . qq| + | . $locale->text('Subtotal') . qq| @@ -1336,9 +1426,6 @@ sub search { {nextsub}> -{login}> -{password}> -
@@ -1376,6 +1463,11 @@ sub create_subtotal_row { sub ar_transactions { $lxdebug->enter_sub(); + $auth->assert('general_ledger | invoice_edit'); + + my ($callback, $href, @columns); + + $form->{customer} = $form->unescape($form->{customer}); ($form->{customer}, $form->{customer_id}) = split(/--/, $form->{customer}); $form->{sort} ||= 'transdate'; @@ -1386,15 +1478,15 @@ sub ar_transactions { my $report = SL::ReportGenerator->new(\%myconfig, $form); - my @columns = + @columns = qw(transdate id type invnumber ordnumber name netamount tax amount paid datepaid due duedate transaction_description notes employee shippingpoint shipvia - globalprojectnumber); + marge_total marge_percent globalprojectnumber); my @hidden_variables = map { "l_${_}" } @columns; - push @hidden_variables, "l_subtotal", qw(open closed customer invnumber ordnumber activity_description notes project_id transdatefrom transdateto); + push @hidden_variables, "l_subtotal", qw(open closed customer invnumber ordnumber transaction_description notes project_id transdatefrom transdateto); - my $href = build_std_url('action=ar_transactions', grep { $form->{$_} } @hidden_variables); + $href = build_std_url('action=ar_transactions', grep { $form->{$_} } @hidden_variables); my %column_defs = ( 'transdate' => { 'text' => $locale->text('Date'), }, @@ -1416,6 +1508,8 @@ sub ar_transactions { 'shippingpoint' => { 'text' => $locale->text('Shipping Point'), }, 'shipvia' => { 'text' => $locale->text('Ship via'), }, 'globalprojectnumber' => { 'text' => $locale->text('Project Number'), }, + 'marge_total' => { 'text' => $locale->text('Ertrag'), }, + 'marge_percent' => { 'text' => $locale->text('Ertrag prozentual'), }, ); foreach my $name (qw(id transdate duedate invnumber ordnumber name datepaid @@ -1433,12 +1527,14 @@ sub ar_transactions { $report->set_export_options('ar_transactions', @hidden_variables); + $report->set_sort_indicator($form->{sort}, 1); + my @options; if ($form->{customer}) { push @options, $locale->text('Customer') . " : $form->{customer}"; } if ($form->{department}) { - ($department) = split /--/, $form->{department}; + my ($department) = split /--/, $form->{department}; push @options, $locale->text('Department') . " : $department"; } if ($form->{invnumber}) { @@ -1480,24 +1576,27 @@ sub ar_transactions { # escape callback for href $callback = $form->escape($href); - my @subtotal_columns = qw(netamount amount paid due); + my @subtotal_columns = qw(netamount amount paid due marge_total marge_percent); my %totals = map { $_ => 0 } @subtotal_columns; my %subtotals = map { $_ => 0 } @subtotal_columns; my $idx = 0; - foreach $ar (@{ $form->{AR} }) { + foreach my $ar (@{ $form->{AR} }) { $ar->{tax} = $ar->{amount} - $ar->{netamount}; $ar->{due} = $ar->{amount} - $ar->{paid}; map { $subtotals{$_} += $ar->{$_}; $totals{$_} += $ar->{$_} } @subtotal_columns; - map { $ar->{$_} = $form->format_amount(\%myconfig, $ar->{$_}, 2) } qw(netamount tax amount paid due); + $subtotals{marge_percent} = $subtotals{netamount} ? ($subtotals{marge_total} * 100 / $subtotals{netamount}) : 0; + $totals{marge_percent} = $totals{netamount} ? ($totals{marge_total} * 100 / $totals{netamount} ) : 0; - my $is_storno = $ar->{storno} && IS->is_storno(\%myconfig, $form, 'ar'); - my $has_storno = $ar->{storno} && !$is_storno; + map { $ar->{$_} = $form->format_amount(\%myconfig, $ar->{$_}, 2) } qw(netamount tax amount paid due marge_total marge_percent); + + my $is_storno = $ar->{storno} && !$ar->{storno_id}; + my $has_storno = $ar->{storno} && $ar->{storno_id}; $ar->{type} = $has_storno ? $locale->text("Invoice with Storno (abbreviation)") : @@ -1542,31 +1641,15 @@ sub ar_transactions { sub storno { $lxdebug->enter_sub(); + $auth->assert('general_ledger'); + + # don't cancel cancelled transactions if (IS->has_storno(\%myconfig, $form, 'ar')) { $form->{title} = $locale->text("Cancel Accounts Receivables Transaction"); $form->error($locale->text("Transaction has already been cancelled!")); } - # negate amount/taxes - for my $i (1 .. $form->{rowcount}) { - $form->{"amount_$i"} *= -1; - $form->{"tax_$i"} *= -1; - } - - # format things - for my $i (1 .. $form->{rowcount}) { - for (qw(amount tax)) { - $form->{"${_}_$i"} = $form->format_amount(\%myconfig, $form->{"${_}_$i"}, 2) if $form->{"${_}_$i"}; - } - } - - $form->{storno} = 1; - $form->{storno_id} = $form->{id}; - $form->{id} = 0; - - $form->{invnumber} = "Storno-" . $form->{invnumber}; - - post(); + AR->storno($form, \%myconfig, $form->{id}); # saving the history if(!exists $form->{addition} && $form->{id} ne "") { @@ -1576,5 +1659,7 @@ sub storno { } # /saving the history + $form->redirect(sprintf $locale->text("Transaction %d cancelled."), $form->{storno_id}); + $lxdebug->leave_sub(); }