X-Git-Url: http://wagnertech.de/git?a=blobdiff_plain;f=bin%2Fmozilla%2Fdn.pl;h=52ed58b18dc67143ce90f68d109feabe99c270b9;hb=4bd1e2f8b588972f10f92728301feacefd5ee4dd;hp=b15d029283be590ad5deaec4e04f8a01bb876244;hpb=79d30e2e5cceb8b1136e1e3a340a88322ed7b461;p=kivitendo-erp.git diff --git a/bin/mozilla/dn.pl b/bin/mozilla/dn.pl index b15d02928..52ed58b18 100644 --- a/bin/mozilla/dn.pl +++ b/bin/mozilla/dn.pl @@ -41,12 +41,19 @@ use SL::ReportGenerator; require "bin/mozilla/common.pl"; require "bin/mozilla/reportgenerator.pl"; require "bin/mozilla/io.pl"; -require "bin/mozilla/arap.pl"; + +use strict; 1; sub edit_config { - $lxdebug->enter_sub(); + $main::lxdebug->enter_sub(); + + my $form = $main::form; + my %myconfig = %main::myconfig; + my $locale = $main::locale; + + $main::auth->assert('config'); DN->get_config(\%myconfig, \%$form); $form->get_lists('charts' => { 'key' => 'ALL_CHARTS', @@ -74,13 +81,19 @@ sub edit_config { $form->{callback} ||= build_std_url("action=edit_config"); $form->header(); - print $form->parse_html_template2("dunning/edit_config"); + print $form->parse_html_template("dunning/edit_config"); - $lxdebug->leave_sub(); + $main::lxdebug->leave_sub(); } sub add { - $lxdebug->enter_sub(); + $main::lxdebug->enter_sub(); + + my $form = $main::form; + my %myconfig = %main::myconfig; + my $locale = $main::locale; + + $main::auth->assert('dunning_edit'); # setup customer selection $form->all_vc(\%myconfig, "customer", "AR"); @@ -89,20 +102,24 @@ sub add { $form->{SHOW_CUSTOMER_SELECTION} = $form->{all_customer} && scalar @{ $form->{all_customer} }; $form->{SHOW_DUNNING_LEVEL_SELECTION} = $form->{DUNNING} && scalar @{ $form->{DUNNING} }; - $form->{SHOW_DEPARTMENT_SELECTION} = $form->{all_departments} && scalar @{ $form->{all_departments} }; + $form->{SHOW_DEPARTMENT_SELECTION} = $form->{all_departments} && scalar @{ $form->{all_departments} || [] }; $form->{title} = $locale->text('Start Dunning Process'); - $form->{jsscript} = 1; - $form->{fokus} = "search.customer"; $form->header(); - print $form->parse_html_template2("dunning/add"); + print $form->parse_html_template("dunning/add"); - $lxdebug->leave_sub(); + $main::lxdebug->leave_sub(); } sub show_invoices { - $lxdebug->enter_sub(); + $main::lxdebug->enter_sub(); + + my $form = $main::form; + my %myconfig = %main::myconfig; + my $locale = $main::locale; + + $main::auth->assert('dunning_edit'); DN->get_invoices(\%myconfig, \%$form); $form->{title} = $locale->text('Start Dunning Process'); @@ -113,7 +130,11 @@ sub show_invoices { if ($row->{next_dunning_config_id}) { map { $_->{SELECTED} = $_->{id} == $row->{next_dunning_config_id} } @{ $row->{DUNNING_CONFIG } }; } - map { $row->{$_} = $form->format_amount(\%myconfig, $row->{$_} * 1, -2) } qw(amount fee interest); + map { $row->{$_} = $form->format_amount(\%myconfig, $row->{$_} * 1, -2) } qw(amount open_amount fee interest); + + if ($row->{'language_id'}) { + $row->{language} = SL::DB::Manager::Language->find_by_or_create('id' => $row->{'language_id'})->{'description'}; + } } $form->get_lists('printers' => 'printers', @@ -121,8 +142,7 @@ sub show_invoices { $form->{type} = 'dunning'; $form->{rowcount} = scalar @{ $form->{DUNNINGS} }; - $form->{jsscript} = 1; - $form->{callback} ||= build_std_url("action=show_invoices", qw(login password customer invnumber ordnumber groupinvoices minamount dunning_level notes)); + $form->{callback} ||= build_std_url("action=show_invoices", qw(customer invnumber ordnumber groupinvoices minamount dunning_level notes)); $form->{PRINT_OPTIONS} = print_options('inline' => 1, 'no_queue' => 1, @@ -131,13 +151,19 @@ sub show_invoices { 'no_opendocument' => 1,); $form->header(); - print $form->parse_html_template2("dunning/show_invoices"); + print $form->parse_html_template("dunning/show_invoices"); - $lxdebug->leave_sub(); + $main::lxdebug->leave_sub(); } sub save { - $lxdebug->enter_sub(); + $main::lxdebug->enter_sub(); + + my $form = $main::form; + my %myconfig = %main::myconfig; + my $locale = $main::locale; + + $main::auth->assert('config'); for my $i (1 .. $form->{rowcount}) { if ($form->{"dunning_description_$i"} ne "") { @@ -151,23 +177,31 @@ sub save { DN->save_config(\%myconfig, \%$form); # saving the history if(!exists $form->{addition} && $form->{id} ne "") { - $form->{snumbers} = qq|dunning_id_| . $form->{"dunning_id"}; + $form->{snumbers} = qq|dunning_id_| . $form->{"dunning_id"}; $form->{addition} = "SAVED FOR DUNNING"; - $form->save_history($form->dbconnect(\%myconfig)); + $form->save_history; } # /saving the history $form->redirect($locale->text('Dunning Process Config saved!')); - $lxdebug->leave_sub(); + $main::lxdebug->leave_sub(); } sub save_dunning { - $lxdebug->enter_sub(); + $main::lxdebug->enter_sub(); + + my $form = $main::form; + my %myconfig = %main::myconfig; + my $locale = $main::locale; + + $main::auth->assert('dunning_edit'); my $active=1; my @rows = (); undef($form->{DUNNING_PDFS}); + my $saved_language_id = $form->{language_id}; + if ($form->{groupinvoices}) { my %dunnings_for; @@ -183,6 +217,7 @@ sub save_dunning { push @{ $level }, { "row" => $i, "invoice_id" => $form->{"inv_id_$i"}, "customer_id" => $form->{"customer_id_$i"}, + "language_id" => $form->{"language_id_$i"}, "next_dunning_config_id" => $form->{"next_dunning_config_id_$i"}, "email" => $form->{"email_$i"}, }; } @@ -190,8 +225,10 @@ sub save_dunning { foreach my $levels (values %dunnings_for) { foreach my $level (values %{ $levels }) { next unless scalar @{ $level }; - - DN->save_dunning(\%myconfig, $form, $level, $userspath, $spool, $sendmail); + if (!$form->{force_lang}) { + $form->{language_id} = @{$level}[0]->{language_id}; + } + DN->save_dunning(\%myconfig, $form, $level); } } @@ -202,21 +239,28 @@ sub save_dunning { my $level = [ { "row" => $i, "invoice_id" => $form->{"inv_id_$i"}, "customer_id" => $form->{"customer_id_$i"}, + "language_id" => $form->{"language_id_$i"}, "next_dunning_config_id" => $form->{"next_dunning_config_id_$i"}, "email" => $form->{"email_$i"}, } ]; - DN->save_dunning(\%myconfig, $form, $level, $userspath, $spool, $sendmail); + if (!$form->{force_lang}) { + $form->{language_id} = @{$level}[0]->{language_id}; + } + DN->save_dunning(\%myconfig, $form, $level); } } - if($form->{DUNNING_PDFS}) { + $form->{language_id} = $saved_language_id; + + if (scalar @{ $form->{DUNNING_PDFS} }) { + $form->{dunning_id} = strftime("%Y%m%d", localtime time) if scalar @{ $form->{DUNNING_PDFS}} > 1; DN->melt_pdfs(\%myconfig, $form, $form->{copies}); } # saving the history if(!exists $form->{addition} && $form->{id} ne "") { - $form->{snumbers} = qq|dunning_id_| . $form->{"dunning_id"}; + $form->{snumbers} = qq|dunning_id_| . $form->{"dunning_id"}; $form->{addition} = "DUNNING STARTED"; - $form->save_history($form->dbconnect(\%myconfig)); + $form->save_history; } # /saving the history @@ -225,24 +269,36 @@ sub save_dunning { $form->redirect($locale->text('Dunning Process started for selected invoices!')); } - $lxdebug->leave_sub(); + $main::lxdebug->leave_sub(); } sub set_email { - $lxdebug->enter_sub(); + $main::lxdebug->enter_sub(); + + my $form = $main::form; + my $locale = $main::locale; + + $main::auth->assert('dunning_edit'); $form->{"title"} = $locale->text("Set eMail text"); - $form->header(); - print($form->parse_html_template2("dunning/set_email")); + $form->header(no_layout => 1); + print($form->parse_html_template("dunning/set_email")); - $lxdebug->leave_sub(); + $main::lxdebug->leave_sub(); } sub search { - $lxdebug->enter_sub(); + $main::lxdebug->enter_sub(); + + my $form = $main::form; + my %myconfig = %main::myconfig; + my $locale = $main::locale; + + $main::auth->assert('dunning_edit'); $form->get_lists("customers" => "ALL_CUSTOMERS", "departments" => "ALL_DEPARTMENTS"); + $form->{ALL_EMPLOYEES} = SL::DB::Manager::Employee->get_all_sorted(query => [ deleted => 0 ]); DN->get_config(\%myconfig, \%$form); @@ -250,27 +306,30 @@ sub search { $form->{SHOW_DEPARTMENT_DDBOX} = scalar @{ $form->{ALL_CUSTOMERS} }; $form->{SHOW_DUNNING_LEVELS} = scalar @{ $form->{DUNNING} }; - $form->{jsscript} = 1; - $form->{title} = $locale->text('Search Dunning'); - $form->{fokus} = "search.customer"; + $form->{title} = $locale->text('Dunnings'); $form->header(); - $form->{onload} = qq|focus()| - . qq|;setupDateFormat('|. $myconfig{dateformat} .qq|', '|. $locale->text("Falsches Datumsformat!") .qq|')| - . qq|;setupPoints('|. $myconfig{numberformat} .qq|', '|. $locale->text("wrongformat") .qq|')|; - - print $form->parse_html_template2("dunning/search"); + print $form->parse_html_template("dunning/search"); - $lxdebug->leave_sub(); + $main::lxdebug->leave_sub(); } sub show_dunning { - $lxdebug->enter_sub(); + $main::lxdebug->enter_sub(); + + my $form = $main::form; + my %myconfig = %main::myconfig; + my $locale = $main::locale; + my $cgi = $::request->{cgi}; + + $main::auth->assert('dunning_edit'); my @filter_field_list = qw(customer_id customer dunning_level department_id invnumber ordnumber - transdatefrom transdateto dunningfrom dunningto notes showold); + transdatefrom transdateto dunningfrom dunningto notes showold l_salesman salesman_id); + + report_generator_set_default_sort('customername', 1); DN->get_dunning(\%myconfig, \%$form); @@ -293,12 +352,13 @@ sub show_dunning { $report->set_options('std_column_visibility' => 1, 'title' => $form->{title}); - $report->set_export_options('show_dunning', @filter_field_list); + $report->set_export_options('show_dunning', @filter_field_list, qw(sort sortdir)); - $report->set_columns( + my %column_defs = ( 'checkbox' => { 'text' => '', 'visible' => 'HTML' }, 'dunning_description' => { 'text' => $locale->text('Dunning Level') }, 'customername' => { 'text' => $locale->text('Customername') }, + 'language' => { 'text' => $locale->text('Language') }, 'invnumber' => { 'text' => $locale->text('Invnumber') }, 'transdate' => { 'text' => $locale->text('Invdate') }, 'duedate' => { 'text' => $locale->text('Invoice Duedate') }, @@ -307,15 +367,24 @@ sub show_dunning { 'dunning_duedate' => { 'text' => $locale->text('Dunning Duedate') }, 'fee' => { 'text' => $locale->text('Total Fees') }, 'interest' => { 'text' => $locale->text('Interest') }, + 'salesman' => { 'text' => $locale->text('Salesperson'), 'visible' => $form->{l_salesman} ? 1 : 0 }, ); - $report->set_column_order(qw(checkbox dunning_description customername invnumber transdate - duedate amount dunning_date dunning_duedate fee interest)); + $report->set_columns(%column_defs); + $report->set_column_order(qw(checkbox dunning_description customername language invnumber transdate + duedate amount dunning_date dunning_duedate fee interest salesman)); + $report->set_sort_indicator($form->{sort}, $form->{sortdir}); - my $edit_url = build_std_url('script=is.pl', 'action=edit', 'callback') . '&id='; - my $print_url = build_std_url('action=print_dunning', 'format=pdf', 'media=screen') . '&dunning_id='; + my $edit_url = sub { build_std_url('script=' . ($_[0]->{invoice} ? 'is' : 'ar') . '.pl', 'action=edit', 'callback') . '&id=' . $::form->escape($_[0]->{id}) }; + my $print_url = sub { build_std_url('action=print_dunning', 'format=pdf', 'media=screen', 'dunning_id='.$_[0]->{dunning_id}, 'language_id=' . $_[0]->{language_id}) }; + my $sort_url = build_std_url('action=show_dunning', grep { $form->{$_} } @filter_field_list); - my %alignment = map { $_ => 'right' } qw(transdate duedate amount dunning_date dunning_duedate fee interest); + foreach my $name (qw(dunning_description customername invnumber transdate duedate dunning_date dunning_duedate salesman)) { + my $sortdir = $form->{sort} eq $name ? 1 - $form->{sortdir} : $form->{sortdir}; + $column_defs{$name}->{link} = $sort_url . "&sort=$name&sortdir=$sortdir"; + } + + my %alignment = map { $_ => 'right' } qw(transdate duedate amount dunning_date dunning_duedate fee interest salesman); my ($current_dunning_rows, $previous_dunning_id, $first_row_for_dunning); @@ -325,7 +394,7 @@ sub show_dunning { my $i = 0; - foreach $ref (@{ $form->{DUNNINGS} }) { + foreach my $ref (@{ $form->{DUNNINGS} }) { $i++; if ($previous_dunning_id != $ref->{dunning_id}) { @@ -334,6 +403,10 @@ sub show_dunning { $first_row_for_dunning = 1; } + if ($ref->{'language_id'}) { + $ref->{language} = SL::DB::Manager::Language->find_by('id' => $ref->{'language_id'})->{'description'}; + } + my $row = { }; foreach my $column (keys %{ $ref }) { $row->{$column} = { @@ -341,8 +414,9 @@ sub show_dunning { 'align' => $alignment{$column}, - 'link' => ($column eq 'invnumber' ? $edit_url . E($ref->{id}) : - $column eq 'dunning_description' ? $print_url . E($ref->{dunning_id}) : ''), + 'link' => ( $column eq 'invnumber' ? $edit_url->($ref) + : $column eq 'dunning_description' ? $print_url->($ref) + : ''), }; } @@ -353,6 +427,13 @@ sub show_dunning { 'align' => 'center', }; + if ($first_row_for_dunning) { + $row->{language} = {'raw_data' => $cgi->hidden('-name' => "language_id_$i", '-value' => $ref->{language_id}) + . " $ref->{language}" }; + } else { + $row->{language} = { }; + } + push @{ $current_dunning_rows }, $row; $previous_dunning_id = $ref->{dunning_id}; @@ -361,8 +442,8 @@ sub show_dunning { $report->add_data($current_dunning_rows) if (scalar @{ $current_dunning_rows }); - $report->set_options('raw_top_info_text' => $form->parse_html_template2('dunning/show_dunning_top'), - 'raw_bottom_info_text' => $form->parse_html_template2('dunning/show_dunning_bottom'), + $report->set_options('raw_top_info_text' => $form->parse_html_template('dunning/show_dunning_top'), + 'raw_bottom_info_text' => $form->parse_html_template('dunning/show_dunning_bottom'), 'output_format' => 'HTML', 'attachment_basename' => $locale->text('dunning_list') . strftime('_%Y%m%d', localtime time), ); @@ -371,28 +452,40 @@ sub show_dunning { $report->generate_with_headers(); - $lxdebug->leave_sub(); + $main::lxdebug->leave_sub(); } sub print_dunning { - $lxdebug->enter_sub(); + $main::lxdebug->enter_sub(); + + my $form = $main::form; + + $main::auth->assert('dunning_edit'); $form->{rowcount} = 1; $form->{selected_1} = 1; $form->{dunning_id_1} = $form->{dunning_id}; + $form->{language_id_1} = $form->{language_id}; print_multiple(); - $lxdebug->leave_sub(); + $main::lxdebug->leave_sub(); } sub print_multiple { - $lxdebug->enter_sub(); + $main::lxdebug->enter_sub(); + + my $form = $main::form; + my %myconfig = %main::myconfig; + my $locale = $main::locale; + + $main::auth->assert('dunning_edit'); $form->{title} = $locale->text('Print dunnings'); my @dunning_ids = map { $form->{"dunning_id_$_"} } grep { $form->{"selected_$_"} } (1..$form->{rowcount}); + my @language_ids = map { $form->{"language_id_$_"} } grep { $form->{"selected_$_"} } (1..$form->{rowcount}); if (!scalar @dunning_ids) { $form->error($locale->text('No dunnings have been selected for printing.')); @@ -400,13 +493,21 @@ sub print_multiple { $form->{DUNNING_PDFS} = []; + my $saved_language_id = $form->{language_id}; + my $i = 0; foreach my $dunning_id (@dunning_ids) { + if (!$form->{force_lang}) { + $form->{language_id} = $language_ids[$i]; + } + $form->{dunning_id} = $dunning_id; DN->print_invoice_for_fees(\%myconfig, $form, $dunning_id); DN->print_dunning(\%myconfig, $form, $dunning_id); + $i++; } + $form->{language_id} = $saved_language_id; if (scalar @{ $form->{DUNNING_PDFS} }) { - $form->{dunning_id} = strftime("%Y%m%d", localtime time); + $form->{dunning_id} = strftime("%Y%m%d", localtime time) if scalar @{ $form->{DUNNING_PDFS}} > 1; DN->melt_pdfs(\%myconfig, $form, $form->{copies}); if ($form->{media} eq 'printer') { @@ -418,7 +519,11 @@ sub print_multiple { $form->redirect($locale->text('Could not print dunning.')); } - $lxdebug->leave_sub(); + $main::lxdebug->leave_sub(); +} + +sub continue { + call_sub($main::form->{nextsub}); } # end of main