X-Git-Url: http://wagnertech.de/git?a=blobdiff_plain;f=bin%2Fmozilla%2Fdn.pl;h=338d86a2348207c2337948c1b599cc33c9423357;hb=786b3862388eb8d4cdcc5dfc663a37fe0e9a82a1;hp=e8e242a61716c2e83a440e336f1bd7725d4f6541;hpb=2c5603bb853ba7892d98c295e1f00641d7c13ef3;p=kivitendo-erp.git diff --git a/bin/mozilla/dn.pl b/bin/mozilla/dn.pl index e8e242a61..338d86a23 100644 --- a/bin/mozilla/dn.pl +++ b/bin/mozilla/dn.pl @@ -31,26 +31,48 @@ # #====================================================================== +use POSIX; + use SL::IS; use SL::PE; use SL::DN; -use Data::Dumper; +use SL::ReportGenerator; require "bin/mozilla/common.pl"; +require "bin/mozilla/reportgenerator.pl"; require "bin/mozilla/io.pl"; -require "bin/mozilla/arap.pl"; 1; sub edit_config { $lxdebug->enter_sub(); + $auth->assert('config'); + DN->get_config(\%myconfig, \%$form); + $form->get_lists('charts' => { 'key' => 'ALL_CHARTS', + 'transdate' => 'current_date' }); + + $form->{SELECT_AR_AMOUNT} = []; + $form->{SELECT_AR} = []; + + foreach my $chart (@{ $form->{ALL_CHARTS} }) { + $chart->{LINKS} = { map { $_, 1 } split m/:/, $chart->{link} }; + + if ($chart->{LINKS}->{AR}) { + $chart->{AR_selected} = "selected" if $chart->{id} == $form->{AR}; + push @{ $form->{SELECT_AR} }, $chart; + } + + if ($chart->{LINKS}->{AR_amount}) { + $chart->{AR_amount_fee_selected} = "selected" if $chart->{id} == $form->{AR_amount_fee}; + $chart->{AR_amount_interest_selected} = "selected" if $chart->{id} == $form->{AR_amount_interest}; + push @{ $form->{SELECT_AR_AMOUNT} }, $chart; + } + } - $form->{title} = $locale->text('Edit Dunning Process Config'); - $form->{callback} ||= build_std_url("action=edit_config"); - $form->{rowcount} = 1 + scalar @{ $form->{DUNNING} }; - $form->{rowcount_odd} = $form->{rowcount} % 2; + $form->{title} = $locale->text('Edit Dunning Process Config'); + $form->{callback} ||= build_std_url("action=edit_config"); $form->header(); print $form->parse_html_template("dunning/edit_config"); @@ -61,6 +83,8 @@ sub edit_config { sub add { $lxdebug->enter_sub(); + $auth->assert('dunning_edit'); + # setup customer selection $form->all_vc(\%myconfig, "customer", "AR"); @@ -83,6 +107,8 @@ sub add { sub show_invoices { $lxdebug->enter_sub(); + $auth->assert('dunning_edit'); + DN->get_invoices(\%myconfig, \%$form); $form->{title} = $locale->text('Start Dunning Process'); @@ -95,11 +121,19 @@ sub show_invoices { map { $row->{$_} = $form->format_amount(\%myconfig, $row->{$_} * 1, -2) } qw(amount fee interest); } + $form->get_lists('printers' => 'printers', + 'languages' => 'languages'); + + $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(1); + $form->{PRINT_OPTIONS} = print_options('inline' => 1, + 'no_queue' => 1, + 'no_postscript' => 1, + 'no_html' => 1, + 'no_opendocument' => 1,); $form->header(); print $form->parse_html_template("dunning/show_invoices"); @@ -110,6 +144,8 @@ sub show_invoices { sub save { $lxdebug->enter_sub(); + $auth->assert('config'); + for my $i (1 .. $form->{rowcount}) { if ($form->{"dunning_description_$i"} ne "") { $form->isblank("dunning_level_$i", $locale->text('Dunning Level missing in row '). $i); @@ -126,7 +162,7 @@ sub save { $form->{addition} = "SAVED FOR DUNNING"; $form->save_history($form->dbconnect(\%myconfig)); } - # /saving the history + # /saving the history $form->redirect($locale->text('Dunning Process Config saved!')); $lxdebug->leave_sub(); @@ -135,6 +171,8 @@ sub save { sub save_dunning { $lxdebug->enter_sub(); + $auth->assert('dunning_edit'); + my $active=1; my @rows = (); undef($form->{DUNNING_PDFS}); @@ -162,7 +200,7 @@ sub save_dunning { foreach my $level (values %{ $levels }) { next unless scalar @{ $level }; - DN->save_dunning(\%myconfig, \%$form, $level, $userspath, $spool, $sendmail); + DN->save_dunning(\%myconfig, $form, $level, $userspath, $spool); } } @@ -175,12 +213,12 @@ sub save_dunning { "customer_id" => $form->{"customer_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); + DN->save_dunning(\%myconfig, $form, $level, $userspath, $spool); } } if($form->{DUNNING_PDFS}) { - DN->melt_pdfs(\%myconfig, \%$form,$spool); + DN->melt_pdfs(\%myconfig, $form, $form->{copies}); } # saving the history @@ -191,7 +229,10 @@ sub save_dunning { } # /saving the history - $form->redirect($locale->text('Dunning Process started for selected invoices!')); + if ($form->{media} eq 'printer') { + delete $form->{callback}; + $form->redirect($locale->text('Dunning Process started for selected invoices!')); + } $lxdebug->leave_sub(); } @@ -199,14 +240,8 @@ sub save_dunning { sub set_email { $lxdebug->enter_sub(); + $auth->assert('dunning_edit'); - my $callback = "$form->{script}?action=set_email&"; - map({ $callback .= "$_=" . $form->escape($form->{$_}) . "&" } - (qw(login password name input_subject input_body input_attachment email_subject email_body email_attachment), grep({ /^[fl]_/ } keys %$form))); - - if ($form->{email_attachment}) { - $form->{email_attachment} = "checked"; - } $form->{"title"} = $locale->text("Set eMail text"); $form->header(); print($form->parse_html_template("dunning/set_email")); @@ -217,6 +252,8 @@ sub set_email { sub search { $lxdebug->enter_sub(); + $auth->assert('dunning_edit'); + $form->get_lists("customers" => "ALL_CUSTOMERS", "departments" => "ALL_DEPARTMENTS"); @@ -226,11 +263,11 @@ 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->{javascript} .= qq||; - $form->header; + $form->{jsscript} = 1; + $form->{title} = $locale->text('Search Dunning'); + $form->{fokus} = "search.customer"; + + $form->header(); $form->{onload} = qq|focus()| . qq|;setupDateFormat('|. $myconfig{dateformat} .qq|', '|. $locale->text("Falsches Datumsformat!") .qq|')| @@ -245,34 +282,109 @@ sub search { sub show_dunning { $lxdebug->enter_sub(); + $auth->assert('dunning_edit'); + + my @filter_field_list = qw(customer_id customer dunning_level department_id invnumber ordnumber + transdatefrom transdateto dunningfrom dunningto notes showold); + DN->get_dunning(\%myconfig, \%$form); - my $odd_even = 0; - my ($previous_dunning_id, $first_row_for_dunning); + if (!$form->{callback}) { + $form->{callback} = build_std_url("action=show_dunning", @filter_field_list); + } + + $form->get_lists('printers' => 'printers', + 'languages' => 'languages'); + + $form->{type} = 'dunning'; + $form->{PRINT_OPTIONS} = print_options('inline' => 1, + 'no_queue' => 1, + 'no_postscript' => 1, + 'no_html' => 1, + 'no_opendocument' => 1,); + $form->{title} = $locale->text('Dunning overview'); + + my $report = SL::ReportGenerator->new(\%myconfig, $form); + + $report->set_options('std_column_visibility' => 1, + 'title' => $form->{title}); + $report->set_export_options('show_dunning', @filter_field_list); + + $report->set_columns( + 'checkbox' => { 'text' => '', 'visible' => 'HTML' }, + 'dunning_description' => { 'text' => $locale->text('Dunning Level') }, + 'customername' => { 'text' => $locale->text('Customername') }, + 'invnumber' => { 'text' => $locale->text('Invnumber') }, + 'transdate' => { 'text' => $locale->text('Invdate') }, + 'duedate' => { 'text' => $locale->text('Invoice Duedate') }, + 'amount' => { 'text' => $locale->text('Amount') }, + 'dunning_date' => { 'text' => $locale->text('Dunning Date') }, + 'dunning_duedate' => { 'text' => $locale->text('Dunning Duedate') }, + 'fee' => { 'text' => $locale->text('Total Fees') }, + 'interest' => { 'text' => $locale->text('Interest') }, + ); + + $report->set_column_order(qw(checkbox dunning_description customername invnumber transdate + duedate amount dunning_date dunning_duedate fee interest)); + + 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 %alignment = map { $_ => 'right' } qw(transdate duedate amount dunning_date dunning_duedate fee interest); + + my ($current_dunning_rows, $previous_dunning_id, $first_row_for_dunning); + + $current_dunning_rows = []; + $first_row_for_dunning = 1; + $form->{rowcount} = scalar @{ $form->{DUNNINGS} }; + + my $i = 0; foreach $ref (@{ $form->{DUNNINGS} }) { + $i++; + if ($previous_dunning_id != $ref->{dunning_id}) { - $odd_even = ($odd_even + 1) % 2; - $ref->{first_row_for_dunning} = 1; + $report->add_data($current_dunning_rows) if (scalar @{ $current_dunning_rows }); + $current_dunning_rows = []; + $first_row_for_dunning = 1; + } - } else { - $ref->{first_row_for_dunning} = 0; + my $row = { }; + foreach my $column (keys %{ $ref }) { + $row->{$column} = { + 'data' => $first_row_for_dunning || (($column ne 'dunning_description') && ($column ne 'customername')) ? $ref->{$column} : '', + + 'align' => $alignment{$column}, + + 'link' => ($column eq 'invnumber' ? $edit_url . E($ref->{id}) : + $column eq 'dunning_description' ? $print_url . E($ref->{dunning_id}) : ''), + }; } - $previous_dunning_id = $ref->{dunning_id}; - $ref->{listrow_odd_even} = $odd_even; - } + $row->{checkbox} = !$first_row_for_dunning ? { } : { + 'raw_data' => $cgi->hidden('-name' => "dunning_id_$i", '-value' => $ref->{dunning_id}) + . $cgi->checkbox('-name' => "selected_$i", '-value' => 1, '-label' => ''), + 'valign' => 'center', + 'align' => 'center', + }; - if (!$form->{callback}) { - $form->{callback} = - build_std_url("action=show_dunning", qw(customer_id customer dunning_level department_id invnumber ordnumber - ransdatefrom transdateto dunningfrom dunningto notes showold)); + push @{ $current_dunning_rows }, $row; + + $previous_dunning_id = $ref->{dunning_id}; + $first_row_for_dunning = 0; } - $form->{title} = $locale->text('Dunning overview'); - $form->header(); + $report->add_data($current_dunning_rows) if (scalar @{ $current_dunning_rows }); + + $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), + ); + + $report->set_options_from_form(); - print $form->parse_html_template("dunning/show_dunning"); + $report->generate_with_headers(); $lxdebug->leave_sub(); @@ -281,17 +393,55 @@ sub show_dunning { sub print_dunning { $lxdebug->enter_sub(); - DN->print_dunning(\%myconfig, \%$form, $form->{dunning_id}, $userspath, $spool, $sendmail); + $auth->assert('dunning_edit'); + + $form->{rowcount} = 1; + $form->{selected_1} = 1; + $form->{dunning_id_1} = $form->{dunning_id}; + + print_multiple(); + + $lxdebug->leave_sub(); +} + +sub print_multiple { + $lxdebug->enter_sub(); + + $auth->assert('dunning_edit'); + + $form->{title} = $locale->text('Print dunnings'); + + my @dunning_ids = map { $form->{"dunning_id_$_"} } grep { $form->{"selected_$_"} } (1..$form->{rowcount}); + + if (!scalar @dunning_ids) { + $form->error($locale->text('No dunnings have been selected for printing.')); + } + + $form->{DUNNING_PDFS} = []; + + foreach my $dunning_id (@dunning_ids) { + DN->print_invoice_for_fees(\%myconfig, $form, $dunning_id); + DN->print_dunning(\%myconfig, $form, $dunning_id); + } + + if (scalar @{ $form->{DUNNING_PDFS} }) { + $form->{dunning_id} = strftime("%Y%m%d", localtime time); + DN->melt_pdfs(\%myconfig, $form, $form->{copies}); + + if ($form->{media} eq 'printer') { + $form->header(); + $form->info($locale->text('The dunnings have been printed.')); + } - if($form->{DUNNING_PDFS}) { - DN->melt_pdfs(\%myconfig, \%$form,$spool); } else { - $form->redirect($locale->text('Could not create dunning copy!')); + $form->redirect($locale->text('Could not print dunning.')); } $lxdebug->leave_sub(); +} +sub continue { + call_sub($form->{nextsub}); } # end of main -