X-Git-Url: http://wagnertech.de/git?a=blobdiff_plain;f=bin%2Fmozilla%2Fdn.pl;h=51e046c8693a135fb16216d5b6a7f89576f1b37e;hb=549f187d3a2b1d15f96c4556714666ed954447bb;hp=a81d9452e6e9fa9b6290ccc2cb904a5e5b41e179;hpb=fec0904532e2136a1a769f568c351f4875257d56;p=kivitendo-erp.git diff --git a/bin/mozilla/dn.pl b/bin/mozilla/dn.pl index a81d9452e..419b4f4bd 100644 --- a/bin/mozilla/dn.pl +++ b/bin/mozilla/dn.pl @@ -24,358 +24,160 @@ # GNU General Public License for more details. # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software -# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, +# MA 02110-1335, USA. #====================================================================== # # Dunning process module # #====================================================================== +use POSIX qw(strftime); + +use List::Util qw(notall); +use List::MoreUtils qw(none); + use SL::IS; -use SL::PE; use SL::DN; -use Data::Dumper; +use SL::DB::Department; +use SL::DB::Dunning; +use SL::File; +use SL::Helper::Flash qw(flash); +use SL::Locale::String qw(t8); +use SL::Presenter::EmailJournal; +use SL::Presenter::FileObject; +use SL::Presenter::WebdavObject; +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', + '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->{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; + setup_dn_edit_config_action_bar(); $form->header(); print $form->parse_html_template("dunning/edit_config"); - $lxdebug->leave_sub(); + $main::lxdebug->leave_sub(); } sub add { - $lxdebug->enter_sub(); - # setup customer selection - $form->all_vc(\%myconfig, "customer", "AR"); + $main::lxdebug->enter_sub(); + + my $form = $main::form; + my %myconfig = %main::myconfig; + my $locale = $main::locale; + + $main::auth->assert('dunning_edit'); DN->get_config(\%myconfig, \%$form); - if (@{ $form->{all_customer} }) { - map { $customer .= "\n" - } (@{ $form->{DUNNING} }); - } - $dunning_level = qq| - - | . $locale->text('Next Dunning Level') . qq| - - - | if $form->{selectdunning_level}; - - # departments - if (@{ $form->{all_departments} }) { - $form->{selectdepartment} = ""; - } - } + $main::lxdebug->enter_sub(); + my $form = $main::form; + my %myconfig = %main::myconfig; + my $locale = $main::locale; - $form->{nextsub} = "save_dunning"; - - $form->{jsscript} = 1; - $form->{javascript} .= qq||; - - $form->{callback} = - "$form->{script}?action=show_invoices&login=$form->{login}&password=$form->{password}&customer=$form->{customer}&invnumber=$form->{invnumber}&ordnumber=$form->{ordnumber}&paymentuntil=$form->{paymentuntil}&groupinvoices=$form->{groupinvoices}&minamount=$form->{minamount}&dunning_level=$form->{dunning_level}¬es=$form->{notes}" - unless $form->{callback}; - - @column_index = qw(dunning_description dunning_description_next active email customername invnumber invdate inv_duedate amount next_duedate fee interest ); - - $column_header{dunning_description} = - qq|| - . $locale->text('Current / Next Level') - . qq||; - $column_header{active} = - qq|| - . NTI($cgi->checkbox('-name' => 'selectall_active', - '-label' => $locale->text('Active?'), - '-checked' => 0, - '-onclick' => "checkbox_check_all('selectall_active', 'active_', 1, " . scalar(@{ $form->{DUNNINGS} }) . ")")) - . qq||; - $column_header{email} = - qq|| - . NTI($cgi->checkbox('-name' => 'selectall_email', - '-label' => $locale->text('eMail?'), - '-checked' => 0, - '-onclick' => "checkbox_check_all('selectall_email', 'email_', 1, " . scalar(@{ $form->{DUNNINGS} }) . ")")) - . qq||; - $column_header{customername} = - qq|| - . $locale->text('Customername') - . qq||; - $column_header{invnumber} = - qq|| - . $locale->text('Invno.') - . qq||; - $column_header{inv_duedate} = - qq|| - . $locale->text('Inv. Duedate') - . qq||; - $column_header{next_duedate} = - qq|| - . $locale->text('Dunning Duedate') - . qq||; - $column_header{invdate} = - qq|| - . $locale->text('Invdate') - . qq||; - $column_header{amount} = - qq|| - . $locale->text('Amount') - . qq||; - $column_header{fee} = - qq|| - . $locale->text('Total Fees') - . qq||; - $column_header{interest} = - qq|| - . $locale->text('Interest') - . qq||; - - $form->header; - - - print qq| - - - -
{script}> - - - - - - - - |; - map { print "$column_header{$_}\n" if $column_header{$_}; } @column_index; - - print qq| - -|; - my $i = 0; - foreach $ref (@{ $form->{DUNNINGS} }) { + $main::auth->assert('dunning_edit'); - $i++; - my $j = $i % 2; + DN->get_invoices(\%myconfig, \%$form); + $form->{title} = $locale->text('Start Dunning Process'); - print qq| - -|; + foreach my $row (@{ $form->{DUNNINGS} }) { + $row->{DUNNING_CONFIG} = [ map +{ %{ $_ } }, @{ $form->{DUNNING_CONFIG} } ]; - $form->{selectdunning} =~ s/ selected//g; - if ($ref->{next_dunning_config_id} ne "") { - $form->{selectdunning} =~ s/value=$ref->{next_dunning_config_id}/value=$ref->{next_dunning_config_id} selected/; + 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 open_amount fee interest); - $column_data{dunning_description} = - qq||; - $column_data{dunning_description_next} = - qq||; - my $active = ($ref->{active}) ? "checked" : ""; - $column_data{active} = - qq||; - my $email = ($ref->{email}) ? "checked" : ""; - $column_data{email} = - qq||; - $column_data{next_duedate} = qq||; - - $column_data{inv_duedate} = qq||; - $column_data{invdate} = qq||; - $column_data{invnumber} = qq||; - $column_data{customername} = qq||; - - map { $column_data{$_} = - qq|| - } qw(amount fee interest); - - map { print "$column_data{$_}\n" } @column_index; - - print qq| - -|; + if ($row->{'language_id'}) { + $row->{language} = SL::DB::Manager::Language->find_by_or_create('id' => $row->{'language_id'})->{'description'}; + } } - $form->{rowcount} = $i; - - print qq| -
$form->{title}
| - . qq|| - . qq|| - . ($ref->{dunning_level} ? $ref->{dunning_level} : " ") - . qq|| - . qq|| - . qq|$ref->{next_duedate}$ref->{duedate}$ref->{transdate}$ref->{invnumber}$ref->{customername}| - . H($form->format_amount(\%myconfig, $ref->{$_} * 1, -2)) - . qq|
- - - -
- -|; - print_options(); - print qq| -
-{script}> - - - - - - + $form->get_lists('printers' => 'printers', + 'languages' => 'languages'); -{login}> -{password}> - - + $form->{type} = 'dunning'; + $form->{rowcount} = scalar @{ $form->{DUNNINGS} }; + $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, + 'no_postscript' => 1, + 'no_html' => 1, + 'no_opendocument' => 1,); - - -|; - - - $lxdebug->leave_sub(); + setup_dn_show_invoices_action_bar(); + $form->header(); + print $form->parse_html_template("dunning/show_invoices"); + $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 "") { @@ -389,24 +191,33 @@ 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 + # /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 = (); + my @status; undef($form->{DUNNING_PDFS}); - if ($form->{groupinvoices}) { + my $saved_language_id = $form->{language_id}; + + if ($form->{groupinvoices} || $form->{l_include_credit_notes}) { my %dunnings_for; for my $i (1 .. $form->{rowcount}) { @@ -420,16 +231,24 @@ sub save_dunning { push @{ $level }, { "row" => $i, "invoice_id" => $form->{"inv_id_$i"}, + "credit_note" => $form->{"credit_note_$i"}, "customer_id" => $form->{"customer_id_$i"}, + "language_id" => $form->{"language_id_$i"}, "next_dunning_config_id" => $form->{"next_dunning_config_id_$i"}, + "print_invoice" => $form->{"include_invoice_$i"}, "email" => $form->{"email_$i"}, }; } 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}; + } + my $rc = DN->save_dunning(\%myconfig, $form, $level); + $rc->{error} =~ s{\n}{
}g if $rc->{error}; + push @status, { invnumbers => [map { $form->{'invnumber_' . $_->{row}} } @$level], + map { ( $_ => $rc->{$_} ) } qw(error dunning_id print_original_invoice send_email), }; } } @@ -440,409 +259,488 @@ 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"}, + "print_invoice" => $form->{"include_invoice_$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}; + } + my $rc = DN->save_dunning(\%myconfig, $form, $level); + $rc->{error} =~ s{\n}{
}g if $rc->{error}; + push @status, { invnumbers => [map { $form->{'invnumber_' . $_->{row}} } @$level], + map { ( $_ => $rc->{$_} ) } qw(error dunning_id print_original_invoice send_email), }; } } - if($form->{DUNNING_PDFS}) { - DN->melt_pdfs(\%myconfig, \%$form,$spool); + $form->{language_id} = $saved_language_id; + + my $pdf_filename; + my $pdf_content; + if ($form->{DUNNING_PDFS} && scalar @{ $form->{DUNNING_PDFS} }) { + $form->{dunning_id} = strftime("%Y%m%d", localtime time) if scalar @{ $form->{DUNNING_PDFS}} > 1; + ($pdf_filename, $pdf_content) = DN->melt_pdfs(\%myconfig, $form, $form->{copies}, return_content => $form->{media} ne 'printer'); + + flash('info', t8('Dunning Process started for selected invoices!')); + if ($form->{media} eq 'printer') { + flash('info', t8('The PDF has been printed')); + } else { + flash('info', t8('The PDF has been created')); + } } # 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 - $form->redirect($locale->text('Dunning Process started for selected invoices!')); + setup_dn_status_action_bar(); + $form->{"title"} = $locale->text("Dunning status"); + $form->header(); + print $form->parse_html_template('dunning/status', { + pdf_filename => $pdf_filename, + pdf_content => $pdf_content, + status => \@status, }); - $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; - 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))); + $main::auth->assert('dunning_edit'); - if ($form->{email_attachment}) { - $form->{email_attachment} = "checked"; - } $form->{"title"} = $locale->text("Set eMail text"); - $form->header(); + $form->header( + no_layout => 1, + use_javascripts => [ qw(ckeditor/ckeditor ckeditor/adapters/jquery) ], + ); print($form->parse_html_template("dunning/set_email")); - $lxdebug->leave_sub(); + $main::lxdebug->leave_sub(); } sub search { - $lxdebug->enter_sub(); - # setup customer selection - $form->all_vc(\%myconfig, "customer", "AR"); + $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); - if (@{ $form->{all_customer} }) { - map { $customer .= "\n" - } (@{ $form->{DUNNING} }); - } - $dunning_level = qq| - - | . $locale->text('Next Dunning Level') . qq| - - - | if $form->{selectdunning_level}; - - # departments - if (@{ $form->{all_departments} }) { - $form->{selectdepartment} = "