1 #=====================================================================
4 # Based on SQL-Ledger Version 2.1.9
5 # Web http://www.lx-office.org
7 #=====================================================================
8 # SQL-Ledger Accounting
9 # Copyright (c) 1998-2002
11 # Author: Dieter Simader
12 # Email: dsimader@sql-ledger.org
13 # Web: http://www.sql-ledger.org
16 # This program is free software; you can redistribute it and/or modify
17 # it under the terms of the GNU General Public License as published by
18 # the Free Software Foundation; either version 2 of the License, or
19 # (at your option) any later version.
21 # This program is distributed in the hope that it will be useful,
22 # but WITHOUT ANY WARRANTY; without even the implied warranty of
23 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24 # GNU General Public License for more details.
25 # You should have received a copy of the GNU General Public License
26 # along with this program; if not, write to the Free Software
27 # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
28 #======================================================================
30 # Dunning process module
32 #======================================================================
39 require "bin/mozilla/common.pl";
40 require "bin/mozilla/io.pl";
41 require "bin/mozilla/arap.pl";
46 $lxdebug->enter_sub();
48 DN->get_config(\%myconfig, \%$form);
50 $form->{title} = $locale->text('Edit Dunning Process Config');
51 $form->{callback} ||= build_std_url("action=edit_config");
52 $form->{rowcount} = 1 + scalar @{ $form->{DUNNING} };
53 $form->{rowcount_odd} = $form->{rowcount} % 2;
56 print $form->parse_html_template("dunning/edit_config");
58 $lxdebug->leave_sub();
62 $lxdebug->enter_sub();
64 # setup customer selection
65 $form->all_vc(\%myconfig, "customer", "AR");
67 DN->get_config(\%myconfig, \%$form);
69 $form->{SHOW_CUSTOMER_SELECTION} = $form->{all_customer} && scalar @{ $form->{all_customer} };
70 $form->{SHOW_DUNNING_LEVEL_SELECTION} = $form->{DUNNING} && scalar @{ $form->{DUNNING} };
71 $form->{SHOW_DEPARTMENT_SELECTION} = $form->{all_departments} && scalar @{ $form->{all_departments} };
73 $form->{title} = $locale->text('Start Dunning Process');
74 $form->{jsscript} = 1;
75 $form->{fokus} = "search.customer";
78 print $form->parse_html_template("dunning/add");
80 $lxdebug->leave_sub();
84 $lxdebug->enter_sub();
86 DN->get_invoices(\%myconfig, \%$form);
87 $form->{title} = $locale->text('Start Dunning Process');
89 foreach my $row (@{ $form->{DUNNINGS} }) {
90 $row->{DUNNING_CONFIG} = [ map +{ %{ $_ } }, @{ $form->{DUNNING_CONFIG} } ];
92 if ($row->{next_dunning_config_id}) {
93 map { $_->{SELECTED} = $_->{id} == $row->{next_dunning_config_id} } @{ $row->{DUNNING_CONFIG } };
95 map { $row->{$_} = $form->format_amount(\%myconfig, $row->{$_} * 1, -2) } qw(amount fee interest);
98 $form->{rowcount} = scalar @{ $form->{DUNNINGS} };
99 $form->{jsscript} = 1;
100 $form->{callback} ||= build_std_url("action=show_invoices", qw(login password customer invnumber ordnumber groupinvoices minamount dunning_level notes));
102 $form->{PRINT_OPTIONS} = print_options(1);
105 print $form->parse_html_template("dunning/show_invoices");
107 $lxdebug->leave_sub();
111 $lxdebug->enter_sub();
113 for my $i (1 .. $form->{rowcount}) {
114 if ($form->{"dunning_description_$i"} ne "") {
115 $form->isblank("dunning_level_$i", $locale->text('Dunning Level missing in row '). $i);
116 $form->isblank("dunning_description_$i", $locale->text('Dunning Description missing in row '). $i);
117 $form->isblank("terms_$i", $locale->text('Terms missing in row '). $i);
118 $form->isblank("payment_terms_$i", $locale->text('Payment Terms missing in row '). $i);
122 DN->save_config(\%myconfig, \%$form);
124 if(!exists $form->{addition} && $form->{id} ne "") {
125 $form->{snumbers} = qq|dunning_id_| . $form->{"dunning_id"};
126 $form->{addition} = "SAVED FOR DUNNING";
127 $form->save_history($form->dbconnect(\%myconfig));
129 # /saving the history
130 $form->redirect($locale->text('Dunning Process Config saved!'));
132 $lxdebug->leave_sub();
136 $lxdebug->enter_sub();
140 undef($form->{DUNNING_PDFS});
142 if ($form->{groupinvoices}) {
145 for my $i (1 .. $form->{rowcount}) {
146 next unless ($form->{"active_$i"});
148 $dunnings_for{$form->{"customer_id_$i"}} ||= {};
149 my $dunning_levels = $dunnings_for{$form->{"customer_id_$i"}};
151 $dunning_levels->{$form->{"next_dunning_config_id_$i"}} ||= [];
152 my $level = $dunning_levels->{$form->{"next_dunning_config_id_$i"}};
154 push @{ $level }, { "row" => $i,
155 "invoice_id" => $form->{"inv_id_$i"},
156 "customer_id" => $form->{"customer_id_$i"},
157 "next_dunning_config_id" => $form->{"next_dunning_config_id_$i"},
158 "email" => $form->{"email_$i"}, };
161 foreach my $levels (values %dunnings_for) {
162 foreach my $level (values %{ $levels }) {
163 next unless scalar @{ $level };
165 DN->save_dunning(\%myconfig, \%$form, $level, $userspath, $spool, $sendmail);
170 for my $i (1 .. $form->{rowcount}) {
171 next unless $form->{"active_$i"};
173 my $level = [ { "row" => $i,
174 "invoice_id" => $form->{"inv_id_$i"},
175 "customer_id" => $form->{"customer_id_$i"},
176 "next_dunning_config_id" => $form->{"next_dunning_config_id_$i"},
177 "email" => $form->{"email_$i"}, } ];
178 DN->save_dunning(\%myconfig, \%$form, $level, $userspath, $spool, $sendmail);
182 if($form->{DUNNING_PDFS}) {
183 DN->melt_pdfs(\%myconfig, \%$form,$spool);
187 if(!exists $form->{addition} && $form->{id} ne "") {
188 $form->{snumbers} = qq|dunning_id_| . $form->{"dunning_id"};
189 $form->{addition} = "DUNNING STARTED";
190 $form->save_history($form->dbconnect(\%myconfig));
192 # /saving the history
194 $form->redirect($locale->text('Dunning Process started for selected invoices!'));
196 $lxdebug->leave_sub();
200 $lxdebug->enter_sub();
203 my $callback = "$form->{script}?action=set_email&";
204 map({ $callback .= "$_=" . $form->escape($form->{$_}) . "&" }
205 (qw(login password name input_subject input_body input_attachment email_subject email_body email_attachment), grep({ /^[fl]_/ } keys %$form)));
207 if ($form->{email_attachment}) {
208 $form->{email_attachment} = "checked";
210 $form->{"title"} = $locale->text("Set eMail text");
212 print($form->parse_html_template("dunning/set_email"));
214 $lxdebug->leave_sub();
218 $lxdebug->enter_sub();
219 # setup customer selection
220 $form->all_vc(\%myconfig, "customer", "AR");
222 DN->get_config(\%myconfig, \%$form);
224 if (@{ $form->{all_customer} }) {
225 map { $customer .= "<option>$_->{name}--$_->{id}\n" }
226 @{ $form->{all_customer} };
227 $customer = qq|<select name=customer><option>\n$customer</select>|;
229 $customer = qq|<input name=customer size=35>|;
233 if (@{ $form->{DUNNING} }) {
234 $form->{selectdunning_level} = "<option></option\n";
236 $form->{selectdunning_level} .=
237 "<option value=$_->{id}>$_->{dunning_description}</option>\n"
238 } (@{ $form->{DUNNING} });
242 <th align=right nowrap>| . $locale->text('Next Dunning Level') . qq|</th>
243 <td colspan=3><select name=dunning_level>$form->{selectdunning_level}</select></td>
245 | if $form->{selectdunning_level};
248 if (@{ $form->{all_departments} }) {
249 $form->{selectdepartment} = "<option>\n";
251 $form->{selectdepartment} .=
252 "<option>$_->{description}--$_->{id}\n"
253 } (@{ $form->{all_departments} });
257 <th align=right nowrap>| . $locale->text('Department') . qq|</th>
258 <td colspan=3><select name=department>$form->{selectdepartment}</select></td>
260 | if $form->{selectdepartment};
261 $form->{title} = $locale->text('Search Dunning');
262 $form->{nextsub} = "show_dunning";
264 # use JavaScript Calendar or not
265 $form->{jsscript} = $jscalendar;
267 if ($form->{jsscript}) {
269 # with JavaScript Calendar
271 <td><input name=transdatefrom id=transdatefrom size=11 title="$myconfig{dateformat}" onBlur=\"check_right_date_format(this)\">
272 <input type=button name=transdatefrom id="trigger1" value=|
273 . $locale->text('button') . qq|></td>
276 <td><input name=transdateto id=transdateto size=11 title="$myconfig{dateformat}" onBlur=\"check_right_date_format(this)\">
277 <input type=button name=transdateto id="trigger2" value=|
278 . $locale->text('button') . qq|></td>
281 <td><input name=dunningfrom id=dunningfrom size=11 title="$myconfig{dateformat}" onBlur=\"check_right_date_format(this)\">
282 <input type=button name=dunningfrom id="trigger3" value=|
283 . $locale->text('button') . qq|></td>
286 <td><input name=dunningto id=dunningto size=11 title="$myconfig{dateformat}" onBlur=\"check_right_date_format(this)\">
287 <input type=button name=dunningto id="trigger4" value=|
288 . $locale->text('button') . qq|></td>
293 Form->write_trigger(\%myconfig, "4", "transdatefrom", "BR", "trigger1", "transdateto", "BR", "trigger2", "dunningfrom", "BR", "trigger3", "dunningto", "BR", "trigger4");
296 # without JavaScript Calendar
298 qq|<td><input name=transdatefrom id=transdatefrom size=11 title="$myconfig{dateformat}" onBlur=\"check_right_date_format(this)\"></td>|;
300 qq|<td><input name=transdateto id=transdateto size=11 title="$myconfig{dateformat}" onBlur=\"check_right_date_format(this)\"></td>|;
302 qq|<td><input name=dunningfrom id=dunningfrom size=11 title="$myconfig{dateformat}" onBlur=\"check_right_date_format(this)\"></td>|;
304 qq|<td><input name=dunningfrom id=dunningto size=11 title="$myconfig{dateformat}" onBlur=\"check_right_date_format(this)\"></td>|;
307 $form->{fokus} = "search.customer";
308 $form->{javascript} .= qq|<script type="text/javascript" src="js/common.js"></script>|;
310 $onload = qq|focus()|;
311 $onload .= qq|;setupDateFormat('|. $myconfig{dateformat} .qq|', '|. $locale->text("Falsches Datumsformat!") .qq|')|;
312 $onload .= qq|;setupPoints('|. $myconfig{numberformat} .qq|', '|. $locale->text("wrongformat") .qq|')|;
315 <body onLoad="$onload">
317 <form method=post name="search" action=$form->{script}>
320 <tr><th class=listtop>$form->{title}</th></tr>
326 <th align=right>| . $locale->text('Customer') . qq|</th>
327 <td colspan=3>$customer</td>
332 <th align=right nowrap>| . $locale->text('Invoice Number') . qq|</th>
333 <td colspan=3><input name=invnumber size=20></td>
336 <th align=right nowrap>| . $locale->text('Order Number') . qq|</th>
337 <td colspan=3><input name=ordnumber size=20></td>
340 <th align=right nowrap>| . $locale->text('Notes') . qq|</th>
341 <td colspan=3><input name=notes size=40></td>
344 <th align=right nowrap>| . $locale->text('Invdate from') . qq|</th>
346 <th align=right nowrap>| . $locale->text('To') . qq|</th>
350 <th align=right nowrap>| . $locale->text('Dunning Date from') . qq|</th>
352 <th align=right nowrap>| . $locale->text('To') . qq|</th>
360 <td><hr size=3 noshade></td>
366 <th align=right nowrap>| . $locale->text('Show old dunnings') . qq|</th>
367 <td><input type=checkbox value=1 name=showold></td>
374 <input type=hidden name=nextsub value=$form->{nextsub}>
376 <input type=hidden name=login value=$form->{login}>
377 <input type=hidden name=password value=$form->{password}>
380 <input class=submit type=submit name=action value="|
381 . $locale->text('Continue') . qq|">
392 $lxdebug->leave_sub();
397 $lxdebug->enter_sub();
399 DN->get_dunning(\%myconfig, \%$form);
400 $form->{title} = $locale->text('Dunning overview');
407 "$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}"
408 unless $form->{callback};
410 @column_index = qw(dunning_description customername invnumber invdate inv_duedate invamount dunning_date next_duedate fee interest );
412 $column_header{dunning_description} =
413 qq|<th class=listheading>|
414 . $locale->text('Dunning Level')
416 $column_header{customername} =
417 qq|<th class=listheading>|
418 . $locale->text('Customername')
420 $column_header{invnumber} =
421 qq|<th class=listheading>|
422 . $locale->text('Invnumber')
424 $column_header{inv_duedate} =
425 qq|<th class=listheading>|
426 . $locale->text('Invoice Duedate')
428 $column_header{dunning_date} =
429 qq|<th class=listheading>|
430 . $locale->text('Dunning Date')
432 $column_header{next_duedate} =
433 qq|<th class=listheading>|
434 . $locale->text('Dunning Duedate')
436 $column_header{invdate} =
437 qq|<th class=listheading>|
438 . $locale->text('Invdate')
440 $column_header{invamount} =
441 qq|<th class=listheading>|
442 . $locale->text('Amount')
444 $column_header{fee} =
445 qq|<th class=listheading>|
446 . $locale->text('Total Fees')
448 $column_header{interest} =
449 qq|<th class=listheading>|
450 . $locale->text('Interest')
458 <script type="text/javascript" src="js/common.js"></script>
459 <script type="text/javascript" src="js/dunning.js"></script>
460 <form method=post action=$form->{script}>
465 <th class=listtop colspan=10>$form->{title}</th>
469 map { print "$column_header{$_}\n" } @column_index;
476 "dunning_duedate" => "next_duedate",
477 "duedate" => "inv_duedate",
478 "transdate" => "invdate",
479 "amount" => "invamount",
484 my ($previous_dunning_id, $first_row_for_dunning);
485 foreach $ref (@{ $form->{DUNNINGS} }) {
488 if ($previous_dunning_id != $ref->{dunning_id}) {
491 $first_row_for_dunning = 1;
493 $first_row_for_dunning = 0;
495 $previous_dunning_id = $ref->{dunning_id};
498 <tr valign=top class=listrow$j>
503 foreach (qw(dunning_date dunning_duedate duedate transdate customername amount fee interest)) {
504 my $col = $columns{$_} ? $columns{$_} : $_;
505 $column_data{$col} = "<td>" . H($ref->{$_}) . "</td>";
508 if ($first_row_for_dunning) {
509 $column_data{dunning_description} =
510 qq|<td><a href="dn.pl?action=print_dunning&format=pdf&media=screen&| .
511 qq|dunning_id=| . E($ref->{dunning_id}) .
512 join("", map({ "&${_}=" . E($form->{$_}) } qw(login password callback))) .
513 qq|">| . H($ref->{dunning_description}) . qq|</a></td>|;
515 $column_data{dunning_description} = qq|<td> </td>|;
516 $column_data{customername} = qq|<td> </td>|;
519 $column_data{invnumber} =
520 qq|<td><a href="| . ($ref->{invoice} ? "is.pl" : "ar.pl" ) .
521 qq|?action=edit&id=| . H($ref->{id}) .
522 join("", map({ "&${_}=" . E($form->{$_}) } qw(login password callback))) .
523 qq|">| . H($ref->{invnumber}) . qq|</a></td>|;
525 map { print "$column_data{$_}\n" } @column_index;
532 $form->{rowcount} = $i;
539 <td><hr size=3 noshade></td>
544 <form method=post action=$form->{script}>
546 <input name=callback type=hidden value="$form->{callback}">
547 <input name=rowcount type=hidden value="$form->{rowcount}">
548 <input name=nextsub type=hidden value="$form->{nextsub}">
551 <input type=hidden name=login value=$form->{login}>
552 <input type=hidden name=password value=$form->{password}>
561 $lxdebug->leave_sub();
566 $lxdebug->enter_sub();
568 DN->print_dunning(\%myconfig, \%$form, $form->{dunning_id}, $userspath, $spool, $sendmail);
570 if($form->{DUNNING_PDFS}) {
571 DN->melt_pdfs(\%myconfig, \%$form,$spool);
573 $form->redirect($locale->text('Could not create dunning copy!'));
576 $lxdebug->leave_sub();