X-Git-Url: http://wagnertech.de/git?a=blobdiff_plain;f=bin%2Fmozilla%2Fap.pl;h=97f2dbad9480ecc449eaafd292a5b1f33e266f2a;hb=088b52b58c46f3c8b0f9a795d6ab840ec127cf0d;hp=2deb9cb5f10586f2b66de3790e7c2840ca1f3906;hpb=09685616f65f95b3189049855dfc53d2bf1ef271;p=kivitendo-erp.git diff --git a/bin/mozilla/ap.pl b/bin/mozilla/ap.pl index 2deb9cb5f..97f2dbad9 100644 --- a/bin/mozilla/ap.pl +++ b/bin/mozilla/ap.pl @@ -46,6 +46,8 @@ require "bin/mozilla/common.pl"; require "bin/mozilla/drafts.pl"; require "bin/mozilla/reportgenerator.pl"; +use strict; + 1; # end of main @@ -79,11 +81,14 @@ require "bin/mozilla/reportgenerator.pl"; # $locale->text('Dec') sub add { - $lxdebug->enter_sub(); + $main::lxdebug->enter_sub(); + + my $form = $main::form; + my %myconfig = %main::myconfig; - $auth->assert('general_ledger'); + $main::auth->assert('general_ledger'); - return $lxdebug->leave_sub() if (load_draft_maybe()); + return $main::lxdebug->leave_sub() if (load_draft_maybe()); $form->{title} = "Add"; @@ -95,41 +100,48 @@ sub add { $form->{transdate} = $form->{initial_transdate}; &display_form; - $lxdebug->leave_sub(); + $main::lxdebug->leave_sub(); } sub edit { - $lxdebug->enter_sub(); + $main::lxdebug->enter_sub(); + + my $form = $main::form; - $auth->assert('general_ledger'); + $main::auth->assert('general_ledger'); $form->{title} = "Edit"; &create_links; &display_form; - $lxdebug->leave_sub(); + $main::lxdebug->leave_sub(); } sub display_form { - $lxdebug->enter_sub(); + $main::lxdebug->enter_sub(); - $auth->assert('general_ledger'); + my $form = $main::form; + + $main::auth->assert('general_ledger'); &form_header; &form_footer; - $lxdebug->leave_sub(); + $main::lxdebug->leave_sub(); } sub create_links { - $lxdebug->enter_sub(); + $main::lxdebug->enter_sub(); + + my $form = $main::form; + my %myconfig = %main::myconfig; - $auth->assert('general_ledger'); + $main::auth->assert('general_ledger'); $form->create_links("AP", \%myconfig, "vendor"); - $taxincluded = $form->{taxincluded}; - $duedate = $form->{duedate}; + my $taxincluded = $form->{taxincluded}; + my $duedate = $form->{duedate}; IR->get_vendor(\%myconfig, \%$form); $form->{taxincluded} = $taxincluded; @@ -144,7 +156,7 @@ sub create_links { $form->{notes} = $form->{intnotes} unless $form->{notes}; # currencies - @curr = split(/:/, $form->{currencies}); + my @curr = split(/:/, $form->{currencies}); chomp $curr[0]; $form->{defaultcurrency} = $curr[0]; @@ -176,15 +188,20 @@ 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(); - $auth->assert('general_ledger'); + my $form = $main::form; + my %myconfig = %main::myconfig; + my $locale = $main::locale; + my $cgi = $main::cgi; - $title = $form->{title}; + $main::auth->assert('general_ledger'); + + my $title = $form->{title}; $form->{title} = $locale->text("$title Accounts Payables Transaction"); $form->{taxincluded} = ($form->{taxincluded}) ? "checked" : ""; @@ -216,12 +233,12 @@ sub form_header { #/show hhistory button # set option selected - foreach $item (qw(vendor currency department)) { + foreach my $item (qw(vendor currency department)) { $form->{"select$item"} =~ s/ selected//; $form->{"select$item"} =~ s/option>\Q$form->{$item}\E/option selected>$form->{$item}/; } - $readonly = ($form->{id}) ? "readonly" : ""; + my $readonly = ($form->{id}) ? "readonly" : ""; $form->{radier} = ($form->current_date(\%myconfig) eq $form->{gldate}) ? 1 : 0; $readonly = ($form->{radier}) ? "" : $readonly; @@ -241,7 +258,7 @@ sub form_header { $form->{creditremaining} = $form->format_amount(\%myconfig, $form->{creditremaining}, 0, "0"); - $exchangerate = qq| + my $exchangerate = qq| {forex}> |; if ($form->{currency} ne $form->{defaultcurrency}) { @@ -260,7 +277,7 @@ sub form_header { } } - $taxincluded = ""; + my $taxincluded = ""; $taxincluded = qq| @@ -270,13 +287,14 @@ sub form_header { |; + my $rows; if (($rows = $form->numtextrows($form->{notes}, 50)) < 2) { $rows = 2; } - $notes = + my $notes = qq||; - $department = qq| + my $department = qq| | . $locale->text('Department') . qq| @@ -285,25 +303,24 @@ sub form_header { | if $form->{selectdepartment}; - $n = ($form->{creditremaining} =~ /-/) ? "0" : "1"; + my $n = ($form->{creditremaining} =~ /-/) ? "0" : "1"; - $vendor = + my $vendor = ($form->{selectvendor}) - ? qq|| + ? qq|| : qq||; my @old_project_ids = (); 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" => "AP" },); map({ $_->{link_split} = [ split(/:/, $_->{link}) ]; } @{ $form->{ALL_CHARTS} }); @@ -356,17 +373,18 @@ selectvendor } | # use JavaScript Calendar or not $form->{jsscript} = 1; - $jsscript = ""; + my $jsscript = ""; + my ($button1, $button2); if ($form->{jsscript}) { # with JavaScript Calendar $button1 = qq| - $readonly + text('button') . qq|> |; $button2 = qq| - $readonly + text('button') . qq|> |; @@ -379,9 +397,9 @@ selectvendor } | # without JavaScript Calendar $button1 = - qq| $readonly|; + qq||; $button2 = - qq| $readonly|; + qq||; } my $follow_up_vc = $form->{vendor}; @@ -393,7 +411,7 @@ selectvendor } | $form->{javascript} .= qq||; $form->header; - $onload = qq|;setupDateFormat('|. $myconfig{dateformat} .qq|', '|. $locale->text("Falsches Datumsformat!") .qq|')|; + my $onload = qq|;setupDateFormat('|. $myconfig{dateformat} .qq|', '|. $locale->text("Falsches Datumsformat!") .qq|')|; $onload .= qq|;setupPoints('|. $myconfig{numberformat} .qq|', '|. $locale->text("wrongformat") .qq|')|; print qq| @@ -426,11 +444,11 @@ selectvendor } | - - - - - {terms}> + + + + + @@ -498,8 +516,6 @@ $jsscript . $locale->text('Amount') . qq| - |; - $amount = $locale->text('Amount'); - $project = $locale->text('Project'); + my $amount = $locale->text('Amount'); + my $project = $locale->text('Project'); - for $i (1 .. $form->{rowcount}) { + for my $i (1 .. $form->{rowcount}) { # format amounts $form->{"amount_$i"} = @@ -535,7 +551,7 @@ $jsscript $selected_taxchart = $taxchart_init unless ($form->{"taxchart_$i"}); - $selectAP_amount = + my $selectAP_amount = NTI($cgi->popup_menu('-name' => "AP_amount_$i", '-id' => "AP_amount_$i", '-style' => 'width:400px', @@ -546,7 +562,7 @@ $jsscript . $cgi->hidden('-name' => "previous_AP_amount_$i", '-default' => $selected_accno_full); - $tax = qq||; - my $korrektur = $form->{"korrektur_$i"} ? 'checked' : ''; - my $projectnumber = NTI($cgi->popup_menu('-name' => "project_id_$i", '-values' => \@project_values, @@ -567,8 +581,7 @@ $jsscript - - + $tax @@ -577,7 +590,7 @@ $jsscript $project = ""; } - $taxlabel = + my $taxlabel = ($form->{taxincluded}) ? $locale->text('Tax Included') : $locale->text('Tax'); @@ -585,7 +598,7 @@ $jsscript $form->{invtotal_unformatted} = $form->{invtotal}; $form->{invtotal} = $form->format_amount(\%myconfig, $form->{invtotal}, 2); - $APselected = + my $APselected = NTI($cgi->popup_menu('-name' => "APselected", '-id' => "APselected", '-style' => 'width:400px', '-values' => \@AP_values, '-labels' => \%AP_labels, @@ -630,19 +643,21 @@ $jsscript |; + my @column_index; if ($form->{currency} eq $form->{defaultcurrency}) { @column_index = qw(datepaid source memo paid AP_paid paid_project_id); } else { @column_index = qw(datepaid source memo paid exchangerate AP_paid paid_project_id); } + my %column_data; $column_data{datepaid} = ""; $column_data{paid} = ""; $column_data{exchangerate} = ""; $column_data{AP_paid} = ""; $column_data{source} = ""; $column_data{memo} = ""; - $column_data{paid_project_id} = ""; + $column_data{paid_project_id} = ""; print " @@ -656,12 +671,12 @@ $jsscript my $totalpaid = 0; $form->{paidaccounts}++ if ($form->{"paid_$form->{paidaccounts}"}); - for $i (1 .. $form->{paidaccounts}) { + for my $i (1 .. $form->{paidaccounts}) { print " "; - $selectAP_paid = + my $selectAP_paid = NTI($cgi->popup_menu('-name' => "AP_paid_$i", '-id' => "AP_paid_$i", '-values' => \@AP_paid_values, @@ -703,7 +718,7 @@ $jsscript $column_data{"exchangerate_$i"} = qq||; $column_data{"datepaid_$i"} = qq||; + |; $column_data{"source_$i"} = qq||; $column_data{"memo_$i"} = @@ -752,13 +767,18 @@ $jsscript
| . $locale->text('Vendor') . qq|$vendor $vendor
| . $locale->text('Tax') . qq|| - . $locale->text('Korrektur') . qq| | . $locale->text('Taxkey') . qq| | @@ -507,10 +523,10 @@ $jsscript
| . + my $tax = qq|| . NTI($cgi->popup_menu('-name' => "taxchart_$i", '-id' => "taxchart_$i", '-style' => 'width:200px', @@ -555,8 +571,6 @@ $jsscript '-default' => $selected_taxchart)) . qq|
$selectAP_amount {"amount_$i"}>{"tax_$i"}>$form->{"tax_$i"}$projectnumber
" . $locale->text('Date') . "" . $locale->text('Amount') . "" . $locale->text('Exch') . "" . $locale->text('Account') . "" . $locale->text('Source') . "" . $locale->text('Memo') . "" . $locale->text('Project Number') . "" . $locale->text('Project Number') . "
$exchangerate -
|; - $lxdebug->leave_sub(); + $main::lxdebug->leave_sub(); } sub form_footer { - $lxdebug->enter_sub(); + $main::lxdebug->enter_sub(); - $auth->assert('general_ledger'); + my $form = $main::form; + my %myconfig = %main::myconfig; + my $locale = $main::locale; + my $cgi = $main::cgi; + + $main::auth->assert('general_ledger'); my $follow_ups_block; if ($form->{id}) { @@ -793,8 +813,8 @@ $follow_ups_block qq|
|); } - $transdate = $form->datetonum($form->{transdate}, \%myconfig); - $closedto = $form->datetonum($form->{closedto}, \%myconfig); + my $transdate = $form->datetonum($form->{transdate}, \%myconfig); + my $closedto = $form->datetonum($form->{closedto}, \%myconfig); print qq||; @@ -804,10 +824,10 @@ $follow_ups_block |; } - # ToDO: - insert a global check for stornos, so that a storno is only possible a limited time after saving it + our $total_paid; print qq| | - if ($form->{id} && !IS->has_storno(\%myconfig, $form, 'ap') && !IS->is_storno(\%myconfig, $form, 'ap', $form->{id})); + if ($form->{id} && !IS->has_storno(\%myconfig, $form, 'ap') && !IS->is_storno(\%myconfig, $form, 'ap', $form->{id}) && (($total_paid == 0) || ($total_paid eq ""))); print qq| @@ -823,8 +843,8 @@ $follow_ups_block print qq| |; } # /button for saving history - # mark_as_paid button - if($form->{id} ne "") { + # mark_as_paid button + if($form->{id} ne "") { print qq| |; } # /mark_as_paid button @@ -835,51 +855,58 @@ $follow_ups_block "; - $lxdebug->leave_sub(); + $main::lxdebug->leave_sub(); } sub mark_as_paid { - $lxdebug->enter_sub(); + $main::lxdebug->enter_sub(); + + my $form = $main::form; + my %myconfig = %main::myconfig; - $auth->assert('general_ledger'); + $main::auth->assert('general_ledger'); - &mark_as_paid_common(\%myconfig,"ap"); + &mark_as_paid_common(\%myconfig,"ap"); - $lxdebug->leave_sub(); + $main::lxdebug->leave_sub(); } sub update { - $lxdebug->enter_sub(); + $main::lxdebug->enter_sub(); + + my $form = $main::form; + my %myconfig = %main::myconfig; - $auth->assert('general_ledger'); + $main::auth->assert('general_ledger'); my $display = shift; $form->{invtotal} = 0; + delete @{ $form }{ grep { m/^tax_\d+$/ } keys %{ $form } }; + map { $form->{$_} = $form->parse_amount(\%myconfig, $form->{$_}) } qw(exchangerate creditlimit creditremaining); - @flds = qw(amount AP_amount projectnumber oldprojectnumber project_id); - $count = 0; - for $i (1 .. $form->{rowcount}) { + my @flds = qw(amount AP_amount projectnumber oldprojectnumber project_id taxchart); + my $count = 0; + my (@a, $j, $totaltax); + 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; - if (!$form->{"korrektur_$i"}) { - ($taxkey, $rate) = split(/--/, $form->{"taxchart_$i"}); - if ($taxkey > 1) { - if ($form->{taxincluded}) { - $form->{"tax_$i"} = $form->{"amount_$i"} / ($rate + 1) * $rate; - } else { - $form->{"tax_$i"} = $form->{"amount_$i"} * $rate; - } + my ($taxkey, $rate) = split(/--/, $form->{"taxchart_$i"}); + if ($taxkey > 1) { + if ($form->{taxincluded}) { + $form->{"tax_$i"} = $form->{"amount_$i"} / ($rate + 1) * $rate; } else { - $form->{"tax_$i"} = 0; + $form->{"tax_$i"} = $form->{"amount_$i"} * $rate; } + } else { + $form->{"tax_$i"} = 0; } $form->{"tax_$i"} = $form->round_amount($form->{"tax_$i"}, 2); @@ -896,16 +923,24 @@ sub update { $form->{exchangerate} = $form->{forex} if $form->{forex}; $form->{invdate} = $form->{transdate}; - $save_AP = $form->{AP}; - &check_name("vendor"); - $form->{AP} = $save_AP; + my %saved_variables = map +( $_ => $form->{$_} ), qw(AP AP_amount_1 taxchart_1); + + my $vendor_changed = &check_name("vendor"); + + $form->{AP} = $saved_variables{AP}; + if ($saved_variables{AP_amount_1} =~ m/.--./) { + map { $form->{$_} = $saved_variables{$_} } qw(AP_amount_1 taxchart_1); + } else { + delete $form->{taxchart_1}; + } $form->{rowcount} = $count + 1; $form->{invtotal} = ($form->{taxincluded}) ? $form->{invtotal} : $form->{invtotal} + $totaltax; - for $i (1 .. $form->{paidaccounts}) { + my $totalpaid; + for my $i (1 .. $form->{paidaccounts}) { if ($form->parse_amount(\%myconfig, $form->{"paid_$i"})) { map { $form->{"${_}_$i"} = @@ -926,24 +961,29 @@ sub update { $form->{oldtotalpaid} = $totalpaid; # notes - $form->{notes} = $form->{intnotes}; + $form->{notes} = $form->{intnotes} if $vendor_changed; &display_form; - $lxdebug->leave_sub(); + $main::lxdebug->leave_sub(); } sub post_payment { - $lxdebug->enter_sub(); + $main::lxdebug->enter_sub(); + + my $form = $main::form; + my %myconfig = %main::myconfig; + my $locale = $main::locale; - $auth->assert('general_ledger'); + $main::auth->assert('general_ledger'); $form->{defaultcurrency} = $form->get_default_currency(\%myconfig); - for $i (1 .. $form->{paidaccounts}) { + our $invdate; + 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!')); @@ -966,26 +1006,30 @@ sub post_payment { $form->error($locale->text('Cannot post payment!')); - $lxdebug->leave_sub(); + $main::lxdebug->leave_sub(); } sub post { - $lxdebug->enter_sub(); + $main::lxdebug->enter_sub(); - $auth->assert('general_ledger'); + my $form = $main::form; + my %myconfig = %main::myconfig; + my $locale = $main::locale; + + $main::auth->assert('general_ledger'); # check if there is a vendor, invoice and due date $form->isblank("transdate", $locale->text("Invoice Date missing!")); $form->isblank("duedate", $locale->text("Due Date missing!")); $form->isblank("vendor", $locale->text('Vendor 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 ($form->date_closed($form->{"transdate"}, \%myconfig)); my $zero_amount_posting = 1; - for $i (1 .. $form->{rowcount}) { + for my $i (1 .. $form->{rowcount}) { if ($form->parse_amount(\%myconfig, $form->{"amount_$i"})) { $zero_amount_posting = 0; last; @@ -998,9 +1042,9 @@ sub post { if ($form->{currency} ne $form->{defaultcurrency}); delete($form->{AP}); - 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!')); @@ -1018,14 +1062,14 @@ sub post { } # if old vendor ne vendor redo form - ($vendor) = split /--/, $form->{vendor}; + my ($vendor) = split /--/, $form->{vendor}; if ($form->{oldvendor} ne "$vendor--$form->{vendor_id}") { &update; exit; } - ($debitaccno, $debittaxkey) = split /--/, $form->{AP_amountselected}; - ($taxkey, $NULL) = split /--/, $form->{taxchartselected}; - ($payablesaccno, $payablestaxkey) = split /--/, $form->{APselected}; + my ($debitaccno, $debittaxkey) = split /--/, $form->{AP_amountselected}; + my ($taxkey, $NULL) = split /--/, $form->{taxchartselected}; + my ($payablesaccno, $payablestaxkey) = split /--/, $form->{APselected}; $form->{AP}{amount_1} = $debitaccno; $form->{AP}{payables} = $payablesaccno; $form->{taxkey} = $taxkey; @@ -1040,19 +1084,22 @@ sub post { $form->{addition} = "POSTED"; $form->save_history($form->dbconnect(\%myconfig)); } - # /saving the history + # /saving the history remove_draft() if $form->{remove_draft}; $form->redirect($locale->text('Transaction posted!')); } $form->error($locale->text('Cannot post transaction!')); - $lxdebug->leave_sub(); + $main::lxdebug->leave_sub(); } sub post_as_new { - $lxdebug->enter_sub(); + $main::lxdebug->enter_sub(); + + my $form = $main::form; + my %myconfig = %main::myconfig; - $auth->assert('general_ledger'); + $main::auth->assert('general_ledger'); $form->{postasnew} = 1; # saving the history @@ -1061,16 +1108,19 @@ sub post_as_new { $form->{addition} = "POSTED AS NEW"; $form->save_history($form->dbconnect(\%myconfig)); } - # /saving the history + # /saving the history &post; - $lxdebug->leave_sub(); + $main::lxdebug->leave_sub(); } sub use_as_template { - $lxdebug->enter_sub(); + $main::lxdebug->enter_sub(); + + my $form = $main::form; + my %myconfig = %main::myconfig; - $auth->assert('general_ledger'); + $main::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; @@ -1078,13 +1128,16 @@ sub use_as_template { $form->{invdate} = $form->current_date(\%myconfig); &update; - $lxdebug->leave_sub(); + $main::lxdebug->leave_sub(); } sub delete { - $lxdebug->enter_sub(); + $main::lxdebug->enter_sub(); - $auth->assert('general_ledger'); + my $form = $main::form; + my $locale = $main::locale; + + $main::auth->assert('general_ledger'); $form->{title} = $locale->text('Confirm!'); @@ -1098,7 +1151,7 @@ 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|; @@ -1119,37 +1172,47 @@ sub delete { |; - $lxdebug->leave_sub(); + $main::lxdebug->leave_sub(); } sub yes { - $lxdebug->enter_sub(); + $main::lxdebug->enter_sub(); + + my $form = $main::form; + my %myconfig = %main::myconfig; + my $locale = $main::locale; - $auth->assert('general_ledger'); + $main::auth->assert('general_ledger'); - if (AP->delete_transaction(\%myconfig, \%$form, $spool)) { + if (AP->delete_transaction(\%myconfig, \%$form, $main::spool)) { # saving the history if(!exists $form->{addition}) { $form->{snumbers} = qq|invnumber_| . $form->{invnumber}; $form->{addition} = "DELETED"; $form->save_history($form->dbconnect(\%myconfig)); } - # /saving the history + # /saving the history $form->redirect($locale->text('Transaction deleted!')); } $form->error($locale->text('Cannot delete transaction!')); - $lxdebug->leave_sub(); + $main::lxdebug->leave_sub(); } sub search { - $lxdebug->enter_sub(); + $main::lxdebug->enter_sub(); - $auth->assert('general_ledger | vendor_invoice_edit'); + my $form = $main::form; + my %myconfig = %main::myconfig; + my $locale = $main::locale; + my $cgi = $main::cgi; + + $main::auth->assert('general_ledger | vendor_invoice_edit'); # setup vendor selection $form->all_vc(\%myconfig, "vendor", "AP"); + my $vendor; if (@{ $form->{all_vendor} }) { map { $vendor .= "