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 if (@{ $form->{DUNNING_CONFIG} }) {
90 foreach $item (@{ $form->{DUNNING_CONFIG} }) {
91 $form->{selectdunning} .=
92 "<option value=$item->{id}>$item->{dunning_description}</option>";
97 $form->{nextsub} = "save_dunning";
99 $form->{jsscript} = 1;
100 $form->{javascript} .= qq|<script type="text/javascript" src="js/checkbox_utils.js"></script>|;
103 "$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}"
104 unless $form->{callback};
106 @column_index = qw(dunning_description dunning_description_next active email customername invnumber invdate inv_duedate amount next_duedate fee interest );
108 $column_header{dunning_description} =
109 qq|<th class="listheading" colspan="2">|
110 . $locale->text('Current / Next Level')
112 $column_header{active} =
113 qq|<th class=listheading>|
114 . NTI($cgi->checkbox('-name' => 'selectall_active',
115 '-label' => $locale->text('Active?'),
117 '-onclick' => "checkbox_check_all('selectall_active', 'active_', 1, " . scalar(@{ $form->{DUNNINGS} }) . ")"))
119 $column_header{email} =
120 qq|<th class=listheading>|
121 . NTI($cgi->checkbox('-name' => 'selectall_email',
122 '-label' => $locale->text('eMail?'),
124 '-onclick' => "checkbox_check_all('selectall_email', 'email_', 1, " . scalar(@{ $form->{DUNNINGS} }) . ")"))
126 $column_header{customername} =
127 qq|<th class=listheading>|
128 . $locale->text('Customername')
130 $column_header{invnumber} =
131 qq|<th class=listheading>|
132 . $locale->text('Invno.')
134 $column_header{inv_duedate} =
135 qq|<th class=listheading>|
136 . $locale->text('Inv. Duedate')
138 $column_header{next_duedate} =
139 qq|<th class=listheading>|
140 . $locale->text('Dunning Duedate')
142 $column_header{invdate} =
143 qq|<th class=listheading>|
144 . $locale->text('Invdate')
146 $column_header{amount} =
147 qq|<th class=listheading>|
148 . $locale->text('Amount')
150 $column_header{fee} =
151 qq|<th class=listheading>|
152 . $locale->text('Total Fees')
154 $column_header{interest} =
155 qq|<th class=listheading>|
156 . $locale->text('Interest')
164 <script type="text/javascript" src="js/common.js"></script>
165 <script type="text/javascript" src="js/dunning.js"></script>
166 <form name=Form method=post action=$form->{script}>
171 <th class=listtop colspan=12>$form->{title}</th>
175 map { print "$column_header{$_}\n" if $column_header{$_}; } @column_index;
181 foreach $ref (@{ $form->{DUNNINGS} }) {
187 <tr valign=top class=listrow$j>
190 $form->{selectdunning} =~ s/ selected//g;
191 if ($ref->{next_dunning_config_id} ne "") {
192 $form->{selectdunning} =~ s/value=$ref->{next_dunning_config_id}/value=$ref->{next_dunning_config_id} selected/;
195 $column_data{dunning_description} =
197 . qq|<input type=hidden name=inv_id_$i size=2 value="$ref->{id}">|
198 . qq|<input type=hidden name=customer_id_$i size=2 value="$ref->{customer_id}">|
199 . ($ref->{dunning_level} ? $ref->{dunning_level} : " ")
201 $column_data{dunning_description_next} =
203 . qq|<select name=next_dunning_config_id_$i>$form->{selectdunning}</select>|
205 my $active = ($ref->{active}) ? "checked" : "";
206 $column_data{active} =
207 qq|<td><input type=checkbox name=active_$i value=1 $active></td>|;
208 my $email = ($ref->{email}) ? "checked" : "";
209 $column_data{email} =
210 qq|<td><input type=checkbox name=email_$i value=1 $email></td>|;
211 $column_data{next_duedate} = qq|<td>$ref->{next_duedate}</td>|;
213 $column_data{inv_duedate} = qq|<td><input type=hidden name=inv_duedate_$i size=6 value="$ref->{duedate}">$ref->{duedate}</td>|;
214 $column_data{invdate} = qq|<td><input type=hidden name=invdate_$i size=6 value="$ref->{transdate}">$ref->{transdate}</td>|;
215 $column_data{invnumber} = qq|<td><input type=hidden name=invnumber_$i size=6 value="$ref->{invnumber}">$ref->{invnumber}</td>|;
216 $column_data{customername} = qq|<td><input type=hidden name=customername_$i size=6 value="$ref->{customername}">$ref->{customername}</td>|;
218 map { $column_data{$_} =
219 qq|<td align="right">|
220 . H($form->format_amount(\%myconfig, $ref->{$_} * 1, -2))
222 } qw(amount fee interest);
224 map { print "$column_data{$_}\n" } @column_index;
231 $form->{rowcount} = $i;
238 <td><hr size=3 noshade></td>
244 <form method=post action=$form->{script}>
246 <input name=callback type=hidden value="$form->{callback}">
247 <input name=rowcount type=hidden value="$form->{rowcount}">
248 <input name=nextsub type=hidden value="$form->{nextsub}">
249 <input name=groupinvoices type=hidden value="$form->{groupinvoices}">
252 <input type=hidden name=login value=$form->{login}>
253 <input type=hidden name=password value=$form->{password}>
254 <input type="hidden" name="action">
255 <input type="submit" name="dummy" value="|
256 . $locale->text('Continue') . qq|" onclick="this.disabled=true; this.value='| . $locale->text("The dunning process started") . qq|'; document.Form.action.value='| . $locale->text('Continue') . qq|'; document.Form.submit()">
265 $lxdebug->leave_sub();
270 $lxdebug->enter_sub();
272 for my $i (1 .. $form->{rowcount}) {
273 if ($form->{"dunning_description_$i"} ne "") {
274 $form->isblank("dunning_level_$i", $locale->text('Dunning Level missing in row '). $i);
275 $form->isblank("dunning_description_$i", $locale->text('Dunning Description missing in row '). $i);
276 $form->isblank("terms_$i", $locale->text('Terms missing in row '). $i);
277 $form->isblank("payment_terms_$i", $locale->text('Payment Terms missing in row '). $i);
281 DN->save_config(\%myconfig, \%$form);
283 if(!exists $form->{addition} && $form->{id} ne "") {
284 $form->{snumbers} = qq|dunning_id_| . $form->{"dunning_id"};
285 $form->{addition} = "SAVED FOR DUNNING";
286 $form->save_history($form->dbconnect(\%myconfig));
288 # /saving the history
289 $form->redirect($locale->text('Dunning Process Config saved!'));
291 $lxdebug->leave_sub();
295 $lxdebug->enter_sub();
299 undef($form->{DUNNING_PDFS});
301 if ($form->{groupinvoices}) {
304 for my $i (1 .. $form->{rowcount}) {
305 next unless ($form->{"active_$i"});
307 $dunnings_for{$form->{"customer_id_$i"}} ||= {};
308 my $dunning_levels = $dunnings_for{$form->{"customer_id_$i"}};
310 $dunning_levels->{$form->{"next_dunning_config_id_$i"}} ||= [];
311 my $level = $dunning_levels->{$form->{"next_dunning_config_id_$i"}};
313 push @{ $level }, { "row" => $i,
314 "invoice_id" => $form->{"inv_id_$i"},
315 "customer_id" => $form->{"customer_id_$i"},
316 "next_dunning_config_id" => $form->{"next_dunning_config_id_$i"},
317 "email" => $form->{"email_$i"}, };
320 foreach my $levels (values %dunnings_for) {
321 foreach my $level (values %{ $levels }) {
322 next unless scalar @{ $level };
324 DN->save_dunning(\%myconfig, \%$form, $level, $userspath, $spool, $sendmail);
329 for my $i (1 .. $form->{rowcount}) {
330 next unless $form->{"active_$i"};
332 my $level = [ { "row" => $i,
333 "invoice_id" => $form->{"inv_id_$i"},
334 "customer_id" => $form->{"customer_id_$i"},
335 "next_dunning_config_id" => $form->{"next_dunning_config_id_$i"},
336 "email" => $form->{"email_$i"}, } ];
337 DN->save_dunning(\%myconfig, \%$form, $level, $userspath, $spool, $sendmail);
341 if($form->{DUNNING_PDFS}) {
342 DN->melt_pdfs(\%myconfig, \%$form,$spool);
346 if(!exists $form->{addition} && $form->{id} ne "") {
347 $form->{snumbers} = qq|dunning_id_| . $form->{"dunning_id"};
348 $form->{addition} = "DUNNING STARTED";
349 $form->save_history($form->dbconnect(\%myconfig));
351 # /saving the history
353 $form->redirect($locale->text('Dunning Process started for selected invoices!'));
355 $lxdebug->leave_sub();
359 $lxdebug->enter_sub();
362 my $callback = "$form->{script}?action=set_email&";
363 map({ $callback .= "$_=" . $form->escape($form->{$_}) . "&" }
364 (qw(login password name input_subject input_body input_attachment email_subject email_body email_attachment), grep({ /^[fl]_/ } keys %$form)));
366 if ($form->{email_attachment}) {
367 $form->{email_attachment} = "checked";
369 $form->{"title"} = $locale->text("Set eMail text");
371 print($form->parse_html_template("dunning/set_email"));
373 $lxdebug->leave_sub();
377 $lxdebug->enter_sub();
378 # setup customer selection
379 $form->all_vc(\%myconfig, "customer", "AR");
381 DN->get_config(\%myconfig, \%$form);
383 if (@{ $form->{all_customer} }) {
384 map { $customer .= "<option>$_->{name}--$_->{id}\n" }
385 @{ $form->{all_customer} };
386 $customer = qq|<select name=customer><option>\n$customer</select>|;
388 $customer = qq|<input name=customer size=35>|;
392 if (@{ $form->{DUNNING} }) {
393 $form->{selectdunning_level} = "<option></option\n";
395 $form->{selectdunning_level} .=
396 "<option value=$_->{id}>$_->{dunning_description}</option>\n"
397 } (@{ $form->{DUNNING} });
401 <th align=right nowrap>| . $locale->text('Next Dunning Level') . qq|</th>
402 <td colspan=3><select name=dunning_level>$form->{selectdunning_level}</select></td>
404 | if $form->{selectdunning_level};
407 if (@{ $form->{all_departments} }) {
408 $form->{selectdepartment} = "<option>\n";
410 $form->{selectdepartment} .=
411 "<option>$_->{description}--$_->{id}\n"
412 } (@{ $form->{all_departments} });
416 <th align=right nowrap>| . $locale->text('Department') . qq|</th>
417 <td colspan=3><select name=department>$form->{selectdepartment}</select></td>
419 | if $form->{selectdepartment};
420 $form->{title} = $locale->text('Search Dunning');
421 $form->{nextsub} = "show_dunning";
423 # use JavaScript Calendar or not
424 $form->{jsscript} = $jscalendar;
426 if ($form->{jsscript}) {
428 # with JavaScript Calendar
430 <td><input name=transdatefrom id=transdatefrom size=11 title="$myconfig{dateformat}" onBlur=\"check_right_date_format(this)\">
431 <input type=button name=transdatefrom id="trigger1" value=|
432 . $locale->text('button') . qq|></td>
435 <td><input name=transdateto id=transdateto size=11 title="$myconfig{dateformat}" onBlur=\"check_right_date_format(this)\">
436 <input type=button name=transdateto id="trigger2" value=|
437 . $locale->text('button') . qq|></td>
440 <td><input name=dunningfrom id=dunningfrom size=11 title="$myconfig{dateformat}" onBlur=\"check_right_date_format(this)\">
441 <input type=button name=dunningfrom id="trigger3" value=|
442 . $locale->text('button') . qq|></td>
445 <td><input name=dunningto id=dunningto size=11 title="$myconfig{dateformat}" onBlur=\"check_right_date_format(this)\">
446 <input type=button name=dunningto id="trigger4" value=|
447 . $locale->text('button') . qq|></td>
452 Form->write_trigger(\%myconfig, "4", "transdatefrom", "BR", "trigger1", "transdateto", "BR", "trigger2", "dunningfrom", "BR", "trigger3", "dunningto", "BR", "trigger4");
455 # without JavaScript Calendar
457 qq|<td><input name=transdatefrom id=transdatefrom size=11 title="$myconfig{dateformat}" onBlur=\"check_right_date_format(this)\"></td>|;
459 qq|<td><input name=transdateto id=transdateto size=11 title="$myconfig{dateformat}" onBlur=\"check_right_date_format(this)\"></td>|;
461 qq|<td><input name=dunningfrom id=dunningfrom size=11 title="$myconfig{dateformat}" onBlur=\"check_right_date_format(this)\"></td>|;
463 qq|<td><input name=dunningfrom id=dunningto size=11 title="$myconfig{dateformat}" onBlur=\"check_right_date_format(this)\"></td>|;
466 $form->{fokus} = "search.customer";
467 $form->{javascript} .= qq|<script type="text/javascript" src="js/common.js"></script>|;
469 $onload = qq|focus()|;
470 $onload .= qq|;setupDateFormat('|. $myconfig{dateformat} .qq|', '|. $locale->text("Falsches Datumsformat!") .qq|')|;
471 $onload .= qq|;setupPoints('|. $myconfig{numberformat} .qq|', '|. $locale->text("wrongformat") .qq|')|;
474 <body onLoad="$onload">
476 <form method=post name="search" action=$form->{script}>
479 <tr><th class=listtop>$form->{title}</th></tr>
485 <th align=right>| . $locale->text('Customer') . qq|</th>
486 <td colspan=3>$customer</td>
491 <th align=right nowrap>| . $locale->text('Invoice Number') . qq|</th>
492 <td colspan=3><input name=invnumber size=20></td>
495 <th align=right nowrap>| . $locale->text('Order Number') . qq|</th>
496 <td colspan=3><input name=ordnumber size=20></td>
499 <th align=right nowrap>| . $locale->text('Notes') . qq|</th>
500 <td colspan=3><input name=notes size=40></td>
503 <th align=right nowrap>| . $locale->text('Invdate from') . qq|</th>
505 <th align=right nowrap>| . $locale->text('To') . qq|</th>
509 <th align=right nowrap>| . $locale->text('Dunning Date from') . qq|</th>
511 <th align=right nowrap>| . $locale->text('To') . qq|</th>
519 <td><hr size=3 noshade></td>
525 <th align=right nowrap>| . $locale->text('Show old dunnings') . qq|</th>
526 <td><input type=checkbox value=1 name=showold></td>
533 <input type=hidden name=nextsub value=$form->{nextsub}>
535 <input type=hidden name=login value=$form->{login}>
536 <input type=hidden name=password value=$form->{password}>
539 <input class=submit type=submit name=action value="|
540 . $locale->text('Continue') . qq|">
551 $lxdebug->leave_sub();
556 $lxdebug->enter_sub();
558 DN->get_dunning(\%myconfig, \%$form);
559 $form->{title} = $locale->text('Dunning overview');
566 "$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}"
567 unless $form->{callback};
569 @column_index = qw(dunning_description customername invnumber invdate inv_duedate invamount dunning_date next_duedate fee interest );
571 $column_header{dunning_description} =
572 qq|<th class=listheading>|
573 . $locale->text('Dunning Level')
575 $column_header{customername} =
576 qq|<th class=listheading>|
577 . $locale->text('Customername')
579 $column_header{invnumber} =
580 qq|<th class=listheading>|
581 . $locale->text('Invnumber')
583 $column_header{inv_duedate} =
584 qq|<th class=listheading>|
585 . $locale->text('Invoice Duedate')
587 $column_header{dunning_date} =
588 qq|<th class=listheading>|
589 . $locale->text('Dunning Date')
591 $column_header{next_duedate} =
592 qq|<th class=listheading>|
593 . $locale->text('Dunning Duedate')
595 $column_header{invdate} =
596 qq|<th class=listheading>|
597 . $locale->text('Invdate')
599 $column_header{invamount} =
600 qq|<th class=listheading>|
601 . $locale->text('Amount')
603 $column_header{fee} =
604 qq|<th class=listheading>|
605 . $locale->text('Total Fees')
607 $column_header{interest} =
608 qq|<th class=listheading>|
609 . $locale->text('Interest')
617 <script type="text/javascript" src="js/common.js"></script>
618 <script type="text/javascript" src="js/dunning.js"></script>
619 <form method=post action=$form->{script}>
624 <th class=listtop colspan=10>$form->{title}</th>
628 map { print "$column_header{$_}\n" } @column_index;
635 "dunning_duedate" => "next_duedate",
636 "duedate" => "inv_duedate",
637 "transdate" => "invdate",
638 "amount" => "invamount",
643 my ($previous_dunning_id, $first_row_for_dunning);
644 foreach $ref (@{ $form->{DUNNINGS} }) {
647 if ($previous_dunning_id != $ref->{dunning_id}) {
650 $first_row_for_dunning = 1;
652 $first_row_for_dunning = 0;
654 $previous_dunning_id = $ref->{dunning_id};
657 <tr valign=top class=listrow$j>
662 foreach (qw(dunning_date dunning_duedate duedate transdate customername amount fee interest)) {
663 my $col = $columns{$_} ? $columns{$_} : $_;
664 $column_data{$col} = "<td>" . H($ref->{$_}) . "</td>";
667 if ($first_row_for_dunning) {
668 $column_data{dunning_description} =
669 qq|<td><a href="dn.pl?action=print_dunning&format=pdf&media=screen&| .
670 qq|dunning_id=| . E($ref->{dunning_id}) .
671 join("", map({ "&${_}=" . E($form->{$_}) } qw(login password callback))) .
672 qq|">| . H($ref->{dunning_description}) . qq|</a></td>|;
674 $column_data{dunning_description} = qq|<td> </td>|;
675 $column_data{customername} = qq|<td> </td>|;
678 $column_data{invnumber} =
679 qq|<td><a href="| . ($ref->{invoice} ? "is.pl" : "ar.pl" ) .
680 qq|?action=edit&id=| . H($ref->{id}) .
681 join("", map({ "&${_}=" . E($form->{$_}) } qw(login password callback))) .
682 qq|">| . H($ref->{invnumber}) . qq|</a></td>|;
684 map { print "$column_data{$_}\n" } @column_index;
691 $form->{rowcount} = $i;
698 <td><hr size=3 noshade></td>
703 <form method=post action=$form->{script}>
705 <input name=callback type=hidden value="$form->{callback}">
706 <input name=rowcount type=hidden value="$form->{rowcount}">
707 <input name=nextsub type=hidden value="$form->{nextsub}">
710 <input type=hidden name=login value=$form->{login}>
711 <input type=hidden name=password value=$form->{password}>
720 $lxdebug->leave_sub();
725 $lxdebug->enter_sub();
727 DN->print_dunning(\%myconfig, \%$form, $form->{dunning_id}, $userspath, $spool, $sendmail);
729 if($form->{DUNNING_PDFS}) {
730 DN->melt_pdfs(\%myconfig, \%$form,$spool);
732 $form->redirect($locale->text('Could not create dunning copy!'));
735 $lxdebug->leave_sub();