X-Git-Url: http://wagnertech.de/git?a=blobdiff_plain;f=bin%2Fmozilla%2Fdn.pl;h=52f6cd55d058c3c8864ff03819c76738167e6a58;hb=12c4c658bc579890462f96832d918337c2b2d484;hp=6cf7354e63bd2caadfb20bc14bbd1b1f9e30faa6;hpb=142891a0098403c82521164d259d8ecd029721a3;p=kivitendo-erp.git diff --git a/bin/mozilla/dn.pl b/bin/mozilla/dn.pl index 6cf7354e6..52f6cd55d 100644 --- a/bin/mozilla/dn.pl +++ b/bin/mozilla/dn.pl @@ -36,342 +36,48 @@ use SL::PE; use SL::DN; use Data::Dumper; -require "$form->{path}/io.pl"; -require "$form->{path}/arap.pl"; +require "bin/mozilla/common.pl"; +require "bin/mozilla/io.pl"; +require "bin/mozilla/arap.pl"; 1; sub edit_config { $lxdebug->enter_sub(); - # edit all dunning config data - - $form->header; DN->get_config(\%myconfig, \%$form); - $form->{title} = $locale->text('Edit Dunning Process Config'); - - $form->{callback} = - "$form->{script}?action=edit_config&path=$form->{path}&login=$form->{login}&password=$form->{password}" - unless $form->{callback}; - - @column_index = qw(dunning_level dunning_description active auto email payment_terms terms fee interest template); - - $column_header{dunning_level} = - qq|| - . $locale->text('Dunning Level') - . qq||; - $column_header{dunning_description} = - qq|| - . $locale->text('Dunning Description') - . qq||; - $column_header{active} = - qq|| - . $locale->text('Active?') - . qq||; - $column_header{auto} = - qq|| - . $locale->text('Auto Send?') - . qq||; - $column_header{email} = - qq|| - . $locale->text('eMail Send?') - . qq||; - $column_header{payment_terms} = - qq|| - . $locale->text('Fristsetzung') - . qq||; - $column_header{terms} = - qq|| - . $locale->text('Duedate +Days') - . qq||; - $column_header{fee} = - qq|| - . $locale->text('Fee') - . qq||; - $column_header{interest} = - qq|| - . $locale->text('Interest Rate') - . qq||; - $column_header{template} = - qq|| - . $locale->text('Template') - . qq||; - print qq| - - - -
{script}> - - - - - - - - |; - map { print "$column_header{$_}\n" } @column_index; - - print qq| - -|; - my $i = 0; - foreach $ref (@{ $form->{DUNNING} }) { - - $i++; - my $j = $i % 2; - - print qq| - -|; - - - $column_data{dunning_level} = - qq||; - $column_data{dunning_description} = qq||; - my $active = ($ref->{active}) ? "checked" : ""; - $column_data{active} = - qq||; - my $email = ($ref->{email}) ? "checked" : ""; - $column_data{email} = - qq||; - - my $auto = ($ref->{auto}) ? "checked" : ""; - $column_data{auto} = - qq||; - $column_data{payment_terms} = qq||; - $column_data{terms} = qq||; - $column_data{fee} = qq||; - $column_data{interest} = qq||; - $column_data{template} = qq||; - - - - map { print "$column_data{$_}\n" } @column_index; - - print qq| - -|; - } - $i++; - my $j = $i % 2; - - print qq| - -|; - - - $column_data{dunning_level} = - qq||; - $column_data{dunning_description} = qq||; - my $active = ""; - $column_data{active} = - qq||; - my $email = ""; - $column_data{email} = - qq||; - my $auto = ""; - $column_data{auto} = - qq||; - $column_data{payment_terms} = qq||; - $column_data{terms} = qq||; - $column_data{fee} = qq||; - $column_data{interest} = qq||; - $column_data{template} = qq||; - - - $form->{rowcount} = $i; - map { print "$column_data{$_}\n" } @column_index; - - print qq| - -|; - - - print qq| -
$form->{title}
$i%
$i%
- - - -
- - - -
-{script}> - - - - -{path}> -{login}> -{password}> - -|; - if ($form->{menubar}) { - require "$form->{path}/menu.pl"; - &menubar; - } - - print qq| + $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->header(); + print $form->parse_html_template("dunning/edit_config"); $lxdebug->leave_sub(); } sub add { $lxdebug->enter_sub(); + # setup customer selection $form->all_vc(\%myconfig, "customer", "AR"); 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} = ""; - } - } - - - $form->{nextsub} = "save_dunning"; - - $form->{callback} = - "$form->{script}?action=show_invoices&path=$form->{path}&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 active email customername invnumber invdate inv_duedate invamount next_duedate fee interest ); - - $column_header{dunning_description} = - qq|| - . $locale->text('Current / Next Level') - . qq||; - $column_header{active} = - qq|| - . $locale->text('Active?') - . qq||; - $column_header{email} = - qq|| - . $locale->text('eMail?') - . 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{invamount} = - qq|| - . $locale->text('Amount') - . qq||; - $column_header{fee} = - qq|| - . $locale->text('Total Fees') - . qq||; - $column_header{interest} = - qq|| - . $locale->text('Total Interest') - . qq||; - - $form->header; - - - print qq| - - - -
{script}> - - - - - - - - |; - map { print "$column_header{$_}\n" } @column_index; - - print qq| - -|; - my $i = 0; - foreach $ref (@{ $form->{DUNNINGS} }) { + foreach my $row (@{ $form->{DUNNINGS} }) { + $row->{DUNNING_CONFIG} = [ map +{ %{ $_ } }, @{ $form->{DUNNING_CONFIG} } ]; - $i++; - my $j = $i % 2; - - print qq| - -|; - - $form->{selectdunning} =~ s/ selected//g; - if ($ref->{next_dunning_id} ne "") { - $form->{selectdunning} =~ s/value=$ref->{next_dunning_id}/value=$ref->{next_dunning_id} selected/; - } - - - $dunning = qq||; - - - $column_data{dunning_description} = qq||; - my $active = "checked"; - $column_data{active} = - qq||; - my $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||; - $column_data{invamount} = qq||; - $column_data{fee} = qq||; - $column_data{interest} = qq||; - - - - map { print "$column_data{$_}\n" } @column_index; - - print qq| - -|; - } - - $form->{rowcount} = $i; - - print qq| -
$form->{title}
$ref->{dunning_level}: $dunning$ref->{next_duedate}$ref->{duedate}$ref->{transdate}$ref->{invnumber}$ref->{customername}$ref->{amount}$ref->{fee}$ref->{interest}
- - - -
- -|; -&print_options; -print qq| -
-{script}> - - - - - - - -{path}> -{login}> -{password}> - -|; - if ($form->{menubar}) { - require "$form->{path}/menu.pl"; - &menubar; + 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); } - print qq| - -
+ $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->{PRINT_OPTIONS} = print_options(1); + $form->header(); + print $form->parse_html_template("dunning/show_invoices"); $lxdebug->leave_sub(); - } sub save { @@ -565,6 +120,13 @@ 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->{addition} = "SAVED FOR DUNNING"; + $form->save_history($form->dbconnect(\%myconfig)); + } + # /saving the history $form->redirect($locale->text('Dunning Process Config saved!')); $lxdebug->leave_sub(); @@ -576,61 +138,71 @@ sub save_dunning { my $active=1; my @rows = (); undef($form->{DUNNING_PDFS}); + if ($form->{groupinvoices}) { - while ($active) { - $lastcustomer = 0; - $form->{inv_ids} = ""; - $active = 0; - @rows = (); - for my $i (1 .. $form->{rowcount}) { - $form->{"active_$i"} *= 1; - $lastcustomer = $form->{"customer_id_$i"} unless ($lastcustomer); - if ($form->{"active_$i"} && ($form->{"customer_id_$i"} == $lastcustomer)) { - if ($form->{inv_ids}) { - $form->{inv_ids} .= qq|,$form->{"inv_id_$i"}|; - } else { - $form->{inv_ids} = qq|($form->{"inv_id_$i"}|; - } - $form->{"active_$i"} = 0; - $form->{"customer_id_$i"} = 0; - push(@rows, $i); - } elsif ($form->{"active_$i"}) { - $active = 1; - } else { - $form->{"customer_id_$i"} = 0; - } - } - if ($form->{inv_ids} ne "") { - $form->{inv_ids} .= ")"; - DN->save_dunning(\%myconfig, \%$form, \@rows, $userspath,$spool, $sendmail); + my %dunnings_for; + + for my $i (1 .. $form->{rowcount}) { + next unless ($form->{"active_$i"}); + + $dunnings_for{$form->{"customer_id_$i"}} ||= {}; + my $dunning_levels = $dunnings_for{$form->{"customer_id_$i"}}; + + $dunning_levels->{$form->{"next_dunning_config_id_$i"}} ||= []; + my $level = $dunning_levels->{$form->{"next_dunning_config_id_$i"}}; + + push @{ $level }, { "row" => $i, + "invoice_id" => $form->{"inv_id_$i"}, + "customer_id" => $form->{"customer_id_$i"}, + "next_dunning_config_id" => $form->{"next_dunning_config_id_$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); } } + } else { for my $i (1 .. $form->{rowcount}) { - if ($form->{"active_$i"}) { - @rows = (); - $form->{inv_ids} = qq|($form->{"inv_id_$i"})|; - push(@rows, $i); - DN->save_dunning(\%myconfig, \%$form, \@rows, $userspath,$spool, $sendmail); - } + next unless $form->{"active_$i"}; + + my $level = [ { "row" => $i, + "invoice_id" => $form->{"inv_id_$i"}, + "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); } } + if($form->{DUNNING_PDFS}) { DN->melt_pdfs(\%myconfig, \%$form,$spool); } + # saving the history + if(!exists $form->{addition} && $form->{id} ne "") { + $form->{snumbers} = qq|dunning_id_| . $form->{"dunning_id"}; + $form->{addition} = "DUNNING STARTED"; + $form->save_history($form->dbconnect(\%myconfig)); + } + # /saving the history + $form->redirect($locale->text('Dunning Process started for selected invoices!')); $lxdebug->leave_sub(); } - + sub set_email { $lxdebug->enter_sub(); my $callback = "$form->{script}?action=set_email&"; map({ $callback .= "$_=" . $form->escape($form->{$_}) . "&" } - (qw(login path password name input_subject input_body input_attachment email_subject email_body email_attachment), grep({ /^[fl]_/ } keys %$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"; @@ -696,22 +268,22 @@ sub search { # with JavaScript Calendar $button1 = qq| - + text('button') . qq|> |; $button2 = qq| - + text('button') . qq|> |; $button3 = qq| - + text('button') . qq|> |; $button4 = qq| - + text('button') . qq|> |; @@ -723,19 +295,24 @@ sub search { # without JavaScript Calendar $button1 = - qq||; + qq||; $button2 = - qq||; - $button1 = - qq||; - $button1 = - qq||; + qq||; + $button3 = + qq||; + $button4 = + qq||; } $form->{fokus} = "search.customer"; + $form->{javascript} .= qq||; $form->header; + $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}> @@ -776,7 +353,6 @@ sub search { $button4 - @@ -797,7 +373,6 @@ sub search { {nextsub}> -{path}> {login}> {password}> @@ -829,7 +404,7 @@ sub show_dunning { $form->{callback} = - "$form->{script}?action=show_dunning&path=$form->{path}&login=$form->{login}&password=$form->{password}&customer=$form->{customer}&invnumber=$form->{invnumber}&ordnumber=$form->{ordnumber}&transdatefrom=$form->{transdatefrom}&transdateto=$form->{transdateto}&dunningfrom=$form->{dunningfrom}&dunningto=$form->{dunningto}¬es=$form->{notes}&showold=$form->{showold}&dunning_level=$form->{dunning_level}" + "$form->{script}?action=show_dunning&login=$form->{login}&password=$form->{password}&customer=$form->{customer}&invnumber=$form->{invnumber}&ordnumber=$form->{ordnumber}&transdatefrom=$form->{transdatefrom}&transdateto=$form->{transdateto}&dunningfrom=$form->{dunningfrom}&dunningto=$form->{dunningto}¬es=$form->{notes}&showold=$form->{showold}&dunning_level=$form->{dunning_level}" unless $form->{callback}; @column_index = qw(dunning_description customername invnumber invdate inv_duedate invamount dunning_date next_duedate fee interest ); @@ -872,7 +447,7 @@ sub show_dunning { . qq||; $column_header{interest} = qq|| - . $locale->text('Total Interest') + . $locale->text('Interest') . qq||; $form->header; @@ -887,7 +462,7 @@ sub show_dunning { - + |; @@ -896,11 +471,28 @@ sub show_dunning { print qq| |; + + my %columns = ( + "dunning_duedate" => "next_duedate", + "duedate" => "inv_duedate", + "transdate" => "invdate", + "amount" => "invamount", + ); + my $i = 0; + my $j = 0; + my ($previous_dunning_id, $first_row_for_dunning); foreach $ref (@{ $form->{DUNNINGS} }) { - $i++; - my $j = $i % 2; + + if ($previous_dunning_id != $ref->{dunning_id}) { + $j++; + $j = $j % 2; + $first_row_for_dunning = 1; + } else { + $first_row_for_dunning = 0; + } + $previous_dunning_id = $ref->{dunning_id}; print qq| @@ -908,23 +500,27 @@ sub show_dunning { - $dunning = qq||; - - - $column_data{dunning_description} = qq||; - my $active = "checked"; - $column_data{dunning_date} = qq||; - $column_data{next_duedate} = qq||; - - $column_data{inv_duedate} = qq||; - $column_data{invdate} = qq||; - $column_data{invnumber} = qq||; - $column_data{customername} = qq||; - $column_data{invamount} = qq||; - $column_data{fee} = qq||; - $column_data{interest} = qq||; + foreach (qw(dunning_date dunning_duedate duedate transdate customername amount fee interest)) { + my $col = $columns{$_} ? $columns{$_} : $_; + $column_data{$col} = ""; + } + if ($first_row_for_dunning) { + $column_data{dunning_description} = + qq||; + } else { + $column_data{dunning_description} = qq||; + $column_data{customername} = qq||; + } + $column_data{invnumber} = + qq||; map { print "$column_data{$_}\n" } @column_index; @@ -952,17 +548,8 @@ sub show_dunning { -{path}> {login}> {password}> -|; - - if ($form->{menubar}) { - require "$form->{path}/menu.pl"; - &menubar; - } - - print qq| @@ -974,5 +561,21 @@ sub show_dunning { $lxdebug->leave_sub(); } + +sub print_dunning { + $lxdebug->enter_sub(); + + DN->print_dunning(\%myconfig, \%$form, $form->{dunning_id}, $userspath, $spool, $sendmail); + + if($form->{DUNNING_PDFS}) { + DN->melt_pdfs(\%myconfig, \%$form,$spool); + } else { + $form->redirect($locale->text('Could not create dunning copy!')); + } + + $lxdebug->leave_sub(); + +} + # end of main
$form->{title}$form->{title}
$ref->{dunning_description}$ref->{dunning_date}$ref->{dunning_duedate}$ref->{duedate}$ref->{transdate}{id}&path=$form->{path}&login=$form->{login}&password=$form->{password}&callback=$form->{callback}>$ref->{invnumber}$ref->{customername}$ref->{amount}$ref->{fee}$ref->{interest}" . H($ref->{$_}) . "| . H($ref->{dunning_description}) . qq|  {id}) . + join("", map({ "&${_}=" . E($form->{$_}) } qw(login password callback))) . + qq|">| . H($ref->{invnumber}) . qq|