X-Git-Url: http://wagnertech.de/git?a=blobdiff_plain;f=bin%2Fmozilla%2Fir.pl;h=d848abc64f2a9c54cb57fe5215a91f7c91a63a7c;hb=b65cc47a206d0b5df78123d9b36c1867928bf684;hp=08b6f1d2f14cf2ec82304797d129698e2931fc51;hpb=d83df93a4dc08d7ecb9047c176b610a5b9cc28ed;p=kivitendo-erp.git diff --git a/bin/mozilla/ir.pl b/bin/mozilla/ir.pl index 08b6f1d2f..d848abc64 100644 --- a/bin/mozilla/ir.pl +++ b/bin/mozilla/ir.pl @@ -31,23 +31,33 @@ # #====================================================================== +use SL::FU; use SL::IR; use SL::IS; use SL::PE; +use List::Util qw(max sum); require "bin/mozilla/io.pl"; +require "bin/mozilla/invoice_io.pl"; require "bin/mozilla/arap.pl"; require "bin/mozilla/common.pl"; require "bin/mozilla/drafts.pl"; +use strict; + 1; # end of main sub add { - $lxdebug->enter_sub(); + $main::lxdebug->enter_sub(); + + my $form = $main::form; + my $locale = $main::locale; + + $main::auth->assert('vendor_invoice_edit'); - return $lxdebug->leave_sub() if (load_draft_maybe()); + return $main::lxdebug->leave_sub() if (load_draft_maybe()); $form->{title} = $locale->text('Add Vendor Invoice'); @@ -55,36 +65,46 @@ sub add { &prepare_invoice; &display_form; - $lxdebug->leave_sub(); + $main::lxdebug->leave_sub(); } sub edit { - $lxdebug->enter_sub(); - + $main::lxdebug->enter_sub(); + + my $form = $main::form; + my $locale = $main::locale; + + $main::auth->assert('vendor_invoice_edit'); + # show history button $form->{javascript} = qq||; #/show hhistory button - + $form->{title} = $locale->text('Edit Vendor Invoice'); &invoice_links; &prepare_invoice; &display_form; - $lxdebug->leave_sub(); + $main::lxdebug->leave_sub(); } sub invoice_links { - $lxdebug->enter_sub(); + $main::lxdebug->enter_sub(); + + my $form = $main::form; + my %myconfig = %main::myconfig; + + $main::auth->assert('vendor_invoice_edit'); # create links - $form->{webdav} = $webdav; + $form->{webdav} = $main::webdav; $form->{jsscript} = 1; $form->create_links("AP", \%myconfig, "vendor"); #quote all_vendor Bug 133 - foreach $ref (@{ $form->{all_vendor} }) { + foreach my $ref (@{ $form->{all_vendor} }) { $ref->{name} = $form->quote($ref->{name}); } @@ -93,6 +113,8 @@ sub invoice_links { $form->{vendor_id} = $form->{all_vendor}->[0]->{id}; } } + + my ($payment_id, $language_id, $taxzone_id); if ($form->{payment_id}) { $payment_id = $form->{payment_id}; } @@ -103,11 +125,11 @@ sub invoice_links { $taxzone_id = $form->{taxzone_id}; } - $cp_id = $form->{cp_id}; + my $cp_id = $form->{cp_id}; IR->get_vendor(\%myconfig, \%$form); IR->retrieve_invoice(\%myconfig, \%$form); $form->{cp_id} = $cp_id; - + if ($payment_id) { $form->{payment_id} = $payment_id; } @@ -118,6 +140,7 @@ sub invoice_links { $form->{taxzone_id} = $taxzone_id; } + my @curr = split(/:/, $form->{currencies}); #seems to be missing map { $form->{selectcurrency} .= "$_\n" } @curr; $form->{oldvendor} = "$form->{vendor}--$form->{vendor_id}"; @@ -135,16 +158,18 @@ sub invoice_links { # forex $form->{forex} = $form->{exchangerate}; - $exchangerate = ($form->{exchangerate}) ? $form->{exchangerate} : 1; + my $exchangerate = ($form->{exchangerate}) ? $form->{exchangerate} : 1; - foreach $key (keys %{ $form->{AP_links} }) { + foreach my $key (keys %{ $form->{AP_links} }) { - foreach $ref (@{ $form->{AP_links}{$key} }) { + foreach my $ref (@{ $form->{AP_links}{$key} }) { $form->{"select$key"} .= "$ref->{accno}--$ref->{description}\n"; } + next unless $form->{acc_trans}{$key}; + if ($key eq "AP_paid") { - for $i (1 .. scalar @{ $form->{acc_trans}{$key} }) { + for my $i (1 .. scalar @{ $form->{acc_trans}{$key} }) { $form->{"AP_paid_$i"} = "$form->{acc_trans}{$key}->[$i-1]->{accno}--$form->{acc_trans}{$key}->[$i-1]->{description}"; @@ -174,24 +199,29 @@ sub invoice_links { ($form->datetonum($form->{invdate}, \%myconfig) <= $form->datetonum($form->{closedto}, \%myconfig)); - $lxdebug->leave_sub(); + $main::lxdebug->leave_sub(); } sub prepare_invoice { - $lxdebug->enter_sub(); + $main::lxdebug->enter_sub(); + + my $form = $main::form; + my %myconfig = %main::myconfig; + + $main::auth->assert('vendor_invoice_edit'); if ($form->{id}) { map { $form->{$_} =~ s/\"/"/g } qw(invnumber ordnumber quonumber); my $i = 0; - foreach $ref (@{ $form->{invoice_details} }) { + foreach my $ref (@{ $form->{invoice_details} }) { $i++; map { $form->{"${_}_$i"} = $ref->{$_} } keys %{$ref}; - ($dec) = ($form->{"sellprice_$i"} =~ /\.(\d+)/); + my ($dec) = ($form->{"sellprice_$i"} =~ /\.(\d+)/); $dec = length $dec; - $decimalplaces = ($dec > 2) ? $dec : 2; + my $decimalplaces = ($dec > 2) ? $dec : 2; $form->{"sellprice_$i"} = $form->format_amount(\%myconfig, $form->{"sellprice_$i"}, @@ -207,17 +237,25 @@ sub prepare_invoice { } } - $lxdebug->leave_sub(); + $main::lxdebug->leave_sub(); } sub form_header { - $lxdebug->enter_sub(); + $main::lxdebug->enter_sub(); + + my $form = $main::form; + my %myconfig = %main::myconfig; + my $locale = $main::locale; + my $cgi = $main::cgi; + + $main::auth->assert('vendor_invoice_edit'); + + push @{ $form->{AJAX} }, CGI::Ajax->new('set_duedate_vendor' => "$form->{script}?action=set_duedate_vendor"); # set option selected - foreach $item (qw(AP vendor currency department)) { + foreach my $item (qw(AP vendor currency department)) { $form->{"select$item"} =~ s/ selected//; - $form->{"select$item"} =~ - s/option>\Q$form->{$item}\E/option selected>$form->{$item}/; + $form->{"select$item"} =~ s/option>\Q$form->{$item}\E/option selected>$form->{$item}/; } $form->{employee_id} = $form->{old_employee_id} if $form->{old_employee_id}; @@ -228,14 +266,14 @@ sub form_header { $form->{creditlimit} = $form->format_amount(\%myconfig, $form->{creditlimit}, 0, "0"); $form->{creditremaining} = $form->format_amount(\%myconfig, $form->{creditremaining}, 0, "0"); - $exchangerate = ""; + my $exchangerate = ""; if ($form->{currency} ne $form->{defaultcurrency}) { if ($form->{forex}) { $exchangerate .= qq| | . $locale->text('Exchangerate') . qq| - $form->{exchangerate}{exchangerate}>\n|; + $form->{exchangerate}{exchangerate}>\n|; } else { $exchangerate .= qq| | . $locale->text('Exchangerate') . qq| - {exchangerate}>\n|; + {exchangerate}>\n|; } } $exchangerate .= qq| {forex}>\n|; @@ -243,14 +281,15 @@ sub form_header { my @old_project_ids = ($form->{"globalproject_id"}); map { push @old_project_ids, $form->{"project_id_$_"} if $form->{"project_id_$_"}; } 1..$form->{"rowcount"}; - $form->get_lists("contacts" => "ALL_CONTACTS", - "projects" => { "key" => "ALL_PROJECTS", - "all" => 0, - "old_id" => \@old_project_ids }, - "taxzones" => "ALL_TAXZONES", - "employees" => "ALL_SALESMEN", - "currencies" => "ALL_CURRENCIES", - "vendors" => "ALL_VENDORS"); + $form->get_lists("contacts" => "ALL_CONTACTS", + "projects" => { "key" => "ALL_PROJECTS", + "all" => 0, + "old_id" => \@old_project_ids }, + "taxzones" => "ALL_TAXZONES", + "employees" => "ALL_SALESMEN", + "currencies" => "ALL_CURRENCIES", + "vendors" => "ALL_VENDORS", + "price_factors" => "ALL_PRICE_FACTORS"); my %labels; my @values = (undef); @@ -278,7 +317,7 @@ sub form_header { } my $globalprojectnumber = NTI($cgi->popup_menu('-name' => 'globalproject_id', '-values' => \@values, '-labels' => \%labels, '-default' => $form->{"globalproject_id"})); - + %labels = (); @values = (); my $i = 0; @@ -286,7 +325,7 @@ sub form_header { push(@values, $item); $labels{$item} = $item; } - + $form->{currency} = $form->{defaultcurrency} unless $form->{currency}; my $currencies; if (scalar @values) { @@ -301,7 +340,6 @@ sub form_header { %labels = (); @values = (); - my $i = 0; foreach my $item (@{ $form->{"ALL_SALESMEN"} }) { push(@values, $item->{"id"}); $labels{$item->{"id"}} = $item->{"name"}; @@ -316,7 +354,6 @@ sub form_header { %labels = (); @values = (); - my $i = 0; foreach my $item (@{ $form->{"ALL_VENDORS"} }) { push(@values, $item->{name}.qq|--|.$item->{"id"}); $labels{$item->{name}.qq|--|.$item->{"id"}} = $item->{"name"}; @@ -330,9 +367,9 @@ sub form_header { (($myconfig{vclimit} <= scalar(@values)) ? qq|| : (NTI($cgi->popup_menu('-name' => 'vendor', '-default' => $form->{oldvendor}, - '-onChange' => 'document.getElementById(\'update_button\').click();', - '-values' => \@values, '-labels' => \%labels, '-style' => 'width: 250px')))) . qq| - + '-onChange' => 'document.getElementById(\'update_button\').click();', + '-values' => \@values, '-labels' => \%labels, '-style' => 'width: 250px')))) . qq| + |; %labels = (); @@ -342,6 +379,7 @@ sub form_header { $labels{$item->{"id"}} = $item->{"description"}; } + my $taxzone; if (!$form->{"id"}) { $taxzone = qq| @@ -361,52 +399,66 @@ sub form_header { |; } - $department = qq| + my $department = qq| | . $locale->text('Department') . qq| $form->{selectdepartment} - -| if $form->{selectdepartment}; + \n| if $form->{selectdepartment}; - $n = ($form->{creditremaining} =~ /-/) ? "0" : "1"; + my $n = ($form->{creditremaining} =~ /-/) ? "0" : "1"; # use JavaScript Calendar or not $form->{jsscript} = 1; - $jsscript = ""; - - $button1 = qq| - - text('button') . qq|>\n|; - $button2 = qq| - - text('button') . qq|>\n|; + my $jsscript = ""; + + my $button1 = qq| + + + + \n|; + +#, 'old_duedate__'' + document.getElementsByName('duedate')[0].value, 'vendor_id__' + document.getElementsByName('vendor_id')[0].value],['duedate'])"> + my $button2 = qq| + + + text('button') . qq|> + \n|; #write Trigger $jsscript = - Form->write_trigger(\%myconfig, "2", "invdate", "BL", "trigger1", + Form->write_trigger(\%myconfig, "2", + "invdate", "BL", "trigger1", "duedate", "BL", "trigger2"); - $form->{"javascript"} .= qq||; - $form->{"javascript"} .= qq||; - $form->{javascript} .= qq||; + my $follow_up_vc = $form->{vendor}; + $follow_up_vc =~ s/--\d*\s*$//; + my $follow_up_trans_info = "$form->{invnumber} ($follow_up_vc)"; + + $form->{javascript} .= qq||; + $form->{javascript} .= qq||; + $form->{javascript} .= qq||; + $form->{javascript} .= qq||; $jsscript .= $form->write_trigger(\%myconfig, 2, "orddate", "BL", "trigger_orddate", "quodate", "BL", "trigger_quodate"); $form->header; - $onload = qq|focus()|; + my $onload = qq|focus()|; $onload .= qq|;setupDateFormat('|. $myconfig{dateformat} .qq|', '|. $locale->text("Falsches Datumsformat!") .qq|')|; $onload .= qq|;setupPoints('|. $myconfig{numberformat} .qq|', '|. $locale->text("wrongformat") .qq|')|; print qq| - -{script}> + + |; - $form->hide_form(qw(id title vc type level creditlimit creditremaining - closedto locked shippted storno storno_id - max_dunning_level dunning_amount)); + $form->hide_form(qw(id title vc type level creditlimit creditremaining closedto locked shippted storno storno_id + max_dunning_level dunning_amount vendor_id oldvendor selectvendor taxaccounts + fxgain_accno fxloss_accno taxpart taxservice cursor_fokus + convert_from_oe_ids convert_from_do_ids), + map { $_.'_rate', $_.'_description' } split / /, $form->{taxaccounts} ); print qq|$form->{saved_message}| if $form->{saved_message}; @@ -419,9 +471,6 @@ sub form_header { $vendors - - - $contact | . $locale->text('Credit Limit') . qq| @@ -443,7 +492,7 @@ sub form_header { $employees - + | . $locale->text('Invoice Number') . qq| @@ -483,31 +532,32 @@ sub form_header { $jsscript -{fxgain_accno}> -{fxloss_accno}> - - - - - - + |; - foreach $item (split / /, $form->{taxaccounts}) { + foreach my $item (split / /, $form->{taxaccounts}) { print qq| {"${item}_rate"}> |; } - $lxdebug->leave_sub(); + $main::lxdebug->leave_sub(); } sub form_footer { - $lxdebug->enter_sub(); + $main::lxdebug->enter_sub(); + + my $form = $main::form; + my %myconfig = %main::myconfig; + my $locale = $main::locale; + my $cgi = $main::cgi; + + $main::auth->assert('vendor_invoice_edit'); $form->{invtotal} = $form->{invsubtotal}; + my ($rows, $introws); if (($rows = $form->numtextrows($form->{notes}, 25, 8)) < 2) { $rows = 2; } @@ -515,14 +565,14 @@ sub form_footer { $introws = 2; } $rows = ($rows > $introws) ? $rows : $introws; - $notes = + my $notes = qq|$form->{notes}|; - $intnotes = + my $intnotes = qq|$form->{intnotes}|; $form->{taxincluded} = ($form->{taxincluded}) ? "checked" : ""; - $taxincluded = ""; + my $taxincluded = ""; if ($form->{taxaccounts}) { $taxincluded = qq| {taxincluded}> | @@ -530,9 +580,10 @@ sub form_footer { |; } + my ($tax, $subtotal); if (!$form->{taxincluded}) { - foreach $item (split / /, $form->{taxaccounts}) { + foreach my $item (split / /, $form->{taxaccounts}) { if ($form->{"${item}_base"}) { $form->{invtotal} += $form->{"${item}_total"} = $form->round_amount( @@ -564,7 +615,7 @@ sub form_footer { } if ($form->{taxincluded}) { - foreach $item (split / /, $form->{taxaccounts}) { + foreach my $item (split / /, $form->{taxaccounts}) { if ($form->{"${item}_base"}) { $form->{"${item}_total"} = $form->round_amount( @@ -603,6 +654,21 @@ sub form_footer { $form->{invtotal} = $form->format_amount(\%myconfig, $form->{invtotal}, 2, 0); + 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| + +|; + } + } + + our $colspan; print qq| @@ -618,6 +684,7 @@ sub form_footer { $notes $intnotes + $follow_ups_block @@ -637,7 +704,8 @@ sub form_footer { |; - if ($webdav) { + my $webdav_list; + if ($main::webdav) { $webdav_list = qq| @@ -649,7 +717,7 @@ sub form_footer { Dateiname Webdavlink |; - foreach $file (@{ $form->{WEBDAV} }) { + foreach my $file (@{ $form->{WEBDAV} }) { $webdav_list .= qq| $file->{name} @@ -673,12 +741,14 @@ sub form_footer { |; + my @column_index; if ($form->{currency} eq $form->{defaultcurrency}) { @column_index = qw(datepaid source memo paid AP_paid); } else { @column_index = qw(datepaid source memo paid exchangerate AP_paid); } + my %column_data; $column_data{datepaid} = "" . $locale->text('Date') . ""; $column_data{paid} = "" . $locale->text('Amount') . ""; $column_data{exchangerate} = "" . $locale->text('Exch') . ""; @@ -698,7 +768,7 @@ sub form_footer { my $totalpaid = 0; $form->{paidaccounts}++ if ($form->{"paid_$form->{paidaccounts}"}); - for $i (1 .. $form->{paidaccounts}) { + for my $i (1 .. $form->{paidaccounts}) { print qq| @@ -718,7 +788,7 @@ sub form_footer { $form->{"exchangerate_$i"} = $form->format_amount(\%myconfig, $form->{"exchangerate_$i"}); - $exchangerate = qq| |; + my $exchangerate = qq| |; if ($form->{currency} ne $form->{defaultcurrency}) { if ($form->{"forex_$i"}) { $exchangerate = @@ -741,9 +811,9 @@ sub form_footer { qq| |; $column_data{"source_$i"} = - qq|{"source_$i"}>|; + qq||; $column_data{"memo_$i"} = - qq|{"memo_$i"}>|; + qq||; map { print qq|$column_data{"${_}_$i"}\n| } @column_index; @@ -782,15 +852,15 @@ sub form_footer { |; - $invdate = $form->datetonum($form->{invdate}, \%myconfig); - $closedto = $form->datetonum($form->{closedto}, \%myconfig); + my $invdate = $form->datetonum($form->{invdate}, \%myconfig); + my $closedto = $form->datetonum($form->{closedto}, \%myconfig); print qq| |; if ($form->{id}) { - my $show_storno = !$form->{storno} && !IS->has_storno(\%myconfig, $form, "ap"); + my $show_storno = !$form->{storno} && !IS->has_storno(\%myconfig, $form, "ap") && (($totalpaid == 0) || ($totalpaid eq "")); print qq| @@ -806,6 +876,9 @@ sub form_footer { } print qq| + |; } @@ -818,7 +891,7 @@ sub form_footer { } print $form->write_trigger(\%myconfig, scalar(@triggers) / 3, @triggers); - $form->hide_form(qw(rowcount callback draft_id draft_description login password)); + $form->hide_form(qw(rowcount callback draft_id draft_description vendor_discount)); # button for saving history if($form->{id} ne "") { @@ -830,62 +903,57 @@ sub form_footer { . qq|">|; } # /button for saving history - # mark_as_paid button - if($form->{id} ne "") { - print qq| |; } # /mark_as_paid button print qq| -
$form->{saved_message}