X-Git-Url: http://wagnertech.de/git?a=blobdiff_plain;f=bin%2Fmozilla%2Fir.pl;h=d848abc64f2a9c54cb57fe5215a91f7c91a63a7c;hb=b65cc47a206d0b5df78123d9b36c1867928bf684;hp=474a6c4fdb4b8435cc3d380009496740e36b37fb;hpb=7e2bf6ca0b5a77130cec0b01cfe263cd04f7e64d;p=kivitendo-erp.git diff --git a/bin/mozilla/ir.pl b/bin/mozilla/ir.pl index 474a6c4fd..d848abc64 100644 --- a/bin/mozilla/ir.pl +++ b/bin/mozilla/ir.pl @@ -31,24 +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(); - $form->{"Watchdog::invdate,duedate,vendor,vendor_id"} = 1; + $main::lxdebug->enter_sub(); + + my $form = $main::form; + my $locale = $main::locale; - return $lxdebug->leave_sub() if (load_draft_maybe()); + $main::auth->assert('vendor_invoice_edit'); + + return $main::lxdebug->leave_sub() if (load_draft_maybe()); $form->{title} = $locale->text('Add Vendor Invoice'); @@ -56,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}); } @@ -94,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}; } @@ -104,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; } @@ -119,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}"; @@ -136,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}"; @@ -175,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"}, @@ -208,79 +237,65 @@ 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}/; - } - - if ($form->{old_employee_id}) { - $form->{employee_id} = $form->{old_employee_id}; - } - if ($form->{old_salesman_id}) { - $form->{salesman_id} = $form->{old_salesman_id}; + $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}; + $form->{salesman_id} = $form->{old_salesman_id} if $form->{old_salesman_id}; $form->{defaultcurrency} = $form->get_default_currency(\%myconfig); + $form->{radier} = ($form->current_date(\%myconfig) eq $form->{gldate}) ? 1 : 0; + $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"); - - $form->{radier} = - ($form->current_date(\%myconfig) eq $form->{gldate}) ? 1 : 0; - - $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 = ""; + my $exchangerate = ""; if ($form->{currency} ne $form->{defaultcurrency}) { if ($form->{forex}) { - $exchangerate .= qq| - | - . $locale->text('Exchangerate') . qq| - $form->{exchangerate}{exchangerate}> -|; + $exchangerate .= qq| | . $locale->text('Exchangerate') . qq| + $form->{exchangerate}{exchangerate}>\n|; } else { - $exchangerate .= qq| - | - . $locale->text('Exchangerate') . qq| - {exchangerate}> -|; + $exchangerate .= qq| | . $locale->text('Exchangerate') . qq| + {exchangerate}>\n|; } } - $exchangerate .= qq| -{forex}> -|; + $exchangerate .= qq| {forex}>\n|; 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"); + 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", + "price_factors" => "ALL_PRICE_FACTORS"); my %labels; my @values = (undef); foreach my $item (@{ $form->{"ALL_CONTACTS"} }) { push(@values, $item->{"cp_id"}); - $labels{$item->{"cp_id"}} = $item->{"cp_name"} . - ($item->{"cp_abteilung"} ? " ($item->{cp_abteilung})" : ""); + $labels{$item->{"cp_id"}} = $item->{"cp_name"} . ($item->{"cp_abteilung"} ? " ($item->{cp_abteilung})" : ""); } my $contact; @@ -288,10 +303,8 @@ sub form_header { $contact = qq| | . $locale->text('Contact Person') . qq| - | . - NTI($cgi->popup_menu('-name' => 'cp_id', '-values' => \@values, '-style' => 'width: 250px', - '-labels' => \%labels, '-default' => $form->{"cp_id"})) - . qq| + | . NTI($cgi->popup_menu('-name' => 'cp_id', '-values' => \@values, '-style' => 'width: 250px', + '-labels' => \%labels, '-default' => $form->{"cp_id"})) . qq| |; } @@ -302,11 +315,9 @@ sub form_header { push(@values, $item->{"id"}); $labels{$item->{"id"}} = $item->{"projectnumber"}; } - my $globalprojectnumber = - NTI($cgi->popup_menu('-name' => 'globalproject_id', '-values' => \@values, - '-labels' => \%labels, - '-default' => $form->{"globalproject_id"})); - + my $globalprojectnumber = NTI($cgi->popup_menu('-name' => 'globalproject_id', '-values' => \@values, '-labels' => \%labels, + '-default' => $form->{"globalproject_id"})); + %labels = (); @values = (); my $i = 0; @@ -314,39 +325,35 @@ sub form_header { push(@values, $item); $labels{$item} = $item; } - + $form->{currency} = $form->{defaultcurrency} unless $form->{currency}; my $currencies; if (scalar @values) { $currencies = qq| | . $locale->text('Currency') . qq| - | . - NTI($cgi->popup_menu('-name' => 'currency', '-default' => $form->{"currency"}, - '-values' => \@values, '-labels' => \%labels)) . qq| + | . NTI($cgi->popup_menu('-name' => 'currency', '-default' => $form->{"currency"}, + '-values' => \@values, '-labels' => \%labels)) . qq| |; } %labels = (); @values = (); - my $i = 0; foreach my $item (@{ $form->{"ALL_SALESMEN"} }) { push(@values, $item->{"id"}); $labels{$item->{"id"}} = $item->{"name"}; } my $employees = qq| - + | . $locale->text('Employee') . qq| - | . - NTI($cgi->popup_menu('-name' => 'employee_id', '-default' => $form->{"employee_id"}, - '-values' => \@values, '-labels' => \%labels)) . qq| + | . NTI($cgi->popup_menu('-name' => 'employee_id', '-default' => $form->{"employee_id"}, + '-values' => \@values, '-labels' => \%labels)) . qq| - |; + |; %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"}; @@ -360,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 = (); @@ -372,16 +379,15 @@ sub form_header { $labels{$item->{"id"}} = $item->{"description"}; } + my $taxzone; if (!$form->{"id"}) { $taxzone = qq| | . $locale->text('Steuersatz') . qq| - | . - NTI($cgi->popup_menu('-name' => 'taxzone_id', '-default' => $form->{"taxzone_id"}, - '-values' => \@values, '-labels' => \%labels, '-style' => 'width: 250px')) . qq| + | . NTI($cgi->popup_menu('-name' => 'taxzone_id', '-default' => $form->{"taxzone_id"}, + '-values' => \@values, '-labels' => \%labels, '-style' => 'width: 250px')) . qq| |; - } else { $taxzone = qq| @@ -393,59 +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|> - |; - $button2 = qq| - - text('button') . qq|> - |; + 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"); + $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}; @@ -458,9 +471,6 @@ sub form_header { $vendors - - - $contact | . $locale->text('Credit Limit') . qq| @@ -482,7 +492,7 @@ sub form_header { $employees - + | . $locale->text('Invoice Number') . qq| @@ -522,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; } @@ -554,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}> | @@ -569,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( @@ -603,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( @@ -642,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| @@ -657,6 +684,7 @@ sub form_footer { $notes $intnotes + $follow_ups_block @@ -676,7 +704,8 @@ sub form_footer { |; - if ($webdav) { + my $webdav_list; + if ($main::webdav) { $webdav_list = qq| @@ -688,7 +717,7 @@ sub form_footer { Dateiname Webdavlink |; - foreach $file (@{ $form->{WEBDAV} }) { + foreach my $file (@{ $form->{WEBDAV} }) { $webdav_list .= qq| $file->{name} @@ -712,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') . ""; @@ -737,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| @@ -757,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 = @@ -780,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; @@ -821,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| @@ -845,6 +876,9 @@ sub form_footer { } print qq| + |; } @@ -857,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 "") { @@ -869,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}