a81d9452e6e9fa9b6290ccc2cb904a5e5b41e179
[kivitendo-erp.git] / bin / mozilla / dn.pl
1 #=====================================================================
2 # LX-Office ERP
3 # Copyright (C) 2006
4 # Based on SQL-Ledger Version 2.1.9
5 # Web http://www.lx-office.org
6 #
7 #=====================================================================
8 # SQL-Ledger Accounting
9 # Copyright (c) 1998-2002
10 #
11 #  Author: Dieter Simader
12 #   Email: dsimader@sql-ledger.org
13 #     Web: http://www.sql-ledger.org
14 #
15 #
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.
20 #
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 #======================================================================
29 #
30 # Dunning process module
31 #
32 #======================================================================
33
34 use SL::IS;
35 use SL::PE;
36 use SL::DN;
37 use Data::Dumper;
38
39 require "bin/mozilla/common.pl";
40 require "bin/mozilla/io.pl";
41 require "bin/mozilla/arap.pl";
42
43 1;
44
45 sub edit_config {
46   $lxdebug->enter_sub();
47
48   DN->get_config(\%myconfig, \%$form);
49
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;
54
55   $form->header();
56   print $form->parse_html_template("dunning/edit_config");
57
58   $lxdebug->leave_sub();
59 }
60
61 sub add {
62   $lxdebug->enter_sub();
63   # setup customer selection
64   $form->all_vc(\%myconfig, "customer", "AR");
65
66   DN->get_config(\%myconfig, \%$form);
67
68   if (@{ $form->{all_customer} }) {
69     map { $customer .= "<option>$_->{name}--$_->{id}\n" }
70       @{ $form->{all_customer} };
71     $customer = qq|<select name=customer><option>\n$customer</select>|;
72   } else {
73     $customer = qq|<input name=customer size=35>|;
74   }
75
76   # dunning levels
77   if (@{ $form->{DUNNING} }) {
78     $form->{selectdunning_level} = "<option></option\n";
79     map {
80       $form->{selectdunning_level} .=
81         "<option value=$_->{id}>$_->{dunning_description}</option>\n"
82     } (@{ $form->{DUNNING} });
83   }
84   $dunning_level = qq| 
85     <tr> 
86     <th align=right nowrap>| . $locale->text('Next Dunning Level') . qq|</th>
87     <td colspan=3><select name=dunning_level>$form->{selectdunning_level}</select></td>
88     </tr>
89     | if $form->{selectdunning_level};
90
91   # departments
92   if (@{ $form->{all_departments} }) {
93     $form->{selectdepartment} = "<option>\n";
94     map {
95       $form->{selectdepartment} .=
96         "<option>$_->{description}--$_->{id}\n"
97     } (@{ $form->{all_departments} });
98   }
99   $department = qq| 
100     <tr> 
101     <th align=right nowrap>| . $locale->text('Department') . qq|</th>
102     <td colspan=3><select name=department>$form->{selectdepartment}</select></td>
103     </tr>
104     | if $form->{selectdepartment};
105
106   $form->{title}       = $locale->text('Start Dunning Process');
107   $form->{nextsub}     = "show_invoices";
108
109   $form->{jsscript}    = 1;
110   $form->{fokus}       = "search.customer";
111   $form->{javascript} .= qq|<script type="text/javascript" src="js/common.js"></script>|;
112   $form->header();
113
114   $onload = qq|focus()|;
115   $onload .= qq|;setupDateFormat('|. $myconfig{dateformat} .qq|', '|. $locale->text("Falsches Datumsformat!") .qq|')|;
116   $onload .= qq|;setupPoints('|. $myconfig{numberformat} .qq|', '|. $locale->text("wrongformat") .qq|')|;
117
118   print qq|
119 <body onLoad="$onload">
120
121 <form method=post name="search" action=$form->{script}>
122
123 <table width=100%>
124   <tr><th class=listtop>$form->{title}</th></tr>
125   <tr height="5"></tr>
126   <tr>
127     <td>
128       <table>
129         <tr>
130           <th align=right>| . $locale->text('Customer') . qq|</th>
131           <td colspan=3>$customer</td>
132         </tr>
133         $dunning_level
134         $department
135         <tr>
136           <th align=right nowrap>| . $locale->text('Invoice Number') . qq|</th>
137           <td colspan=3><input name=invnumber size=20></td>
138         </tr>
139         <tr>
140           <th align=right nowrap>| . $locale->text('Order Number') . qq|</th>
141           <td colspan=3><input name=ordnumber size=20></td>
142         </tr>
143         <tr>
144           <th align=right nowrap>| . $locale->text('Notes') . qq|</th>
145           <td colspan=3><input name=notes size=40></td>
146         </tr>
147       </table>
148     </td>
149   </tr>
150   <tr>
151     <td><hr size=3 noshade></td>
152   </tr>
153   <tr>
154     <td>
155       <table>
156         <tr>
157           <th align=right nowrap>| . $locale->text('Minimum Amount') . qq|</th>
158           <td><input name=minamount size=6></td>
159         </tr>
160         <tr>
161           <th align=right nowrap>| . $locale->text('Group Invoices') . qq|</th>
162           <td><input type=checkbox value=1 name=groupinvoices checked></td>
163         </tr>
164       </table>
165     </td>
166   </tr>
167 </table>
168
169 <input type=hidden name=nextsub value=$form->{nextsub}>
170
171 <input type=hidden name=login value=$form->{login}>
172 <input type=hidden name=password value=$form->{password}>
173
174 <br>
175 <input class=submit type=submit name=action value="|
176     . $locale->text('Continue') . qq|">
177
178 </form>
179
180 </body>
181
182 $jsscript
183
184 </html>
185 |;
186
187   $lxdebug->leave_sub();
188
189 }
190
191 sub show_invoices {
192   $lxdebug->enter_sub();
193
194   DN->get_invoices(\%myconfig, \%$form);
195   $form->{title} = $locale->text('Start Dunning Process');
196
197   if (@{ $form->{DUNNING_CONFIG} }) {
198     foreach $item (@{ $form->{DUNNING_CONFIG} }) {
199         $form->{selectdunning} .=
200           "<option value=$item->{id}>$item->{dunning_description}</option>";
201     }
202   }
203
204
205   $form->{nextsub} = "save_dunning";
206
207   $form->{jsscript} = 1;
208   $form->{javascript} .= qq|<script type="text/javascript" src="js/checkbox_utils.js"></script>|;
209
210   $form->{callback} =
211     "$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}&notes=$form->{notes}"
212     unless $form->{callback};
213
214   @column_index = qw(dunning_description dunning_description_next active email customername invnumber invdate inv_duedate amount next_duedate fee interest );
215
216   $column_header{dunning_description} =
217       qq|<th class="listheading" colspan="2">|
218     . $locale->text('Current / Next Level')
219     . qq|</th>|;
220   $column_header{active} =
221       qq|<th class=listheading>|
222     . NTI($cgi->checkbox('-name' => 'selectall_active',
223                          '-label' => $locale->text('Active?'),
224                          '-checked' => 0,
225                          '-onclick' => "checkbox_check_all('selectall_active', 'active_', 1, " . scalar(@{ $form->{DUNNINGS} }) . ")"))
226     . qq|</th>|;
227   $column_header{email} =
228       qq|<th class=listheading>|
229     . NTI($cgi->checkbox('-name' => 'selectall_email',
230                          '-label' => $locale->text('eMail?'),
231                          '-checked' => 0,
232                          '-onclick' => "checkbox_check_all('selectall_email', 'email_', 1, " . scalar(@{ $form->{DUNNINGS} }) . ")"))
233     . qq|</th>|;
234   $column_header{customername} =
235       qq|<th class=listheading>|
236     . $locale->text('Customername')
237     . qq|</th>|;
238   $column_header{invnumber} =
239       qq|<th class=listheading>|
240     . $locale->text('Invno.')
241     . qq|</th>|;
242   $column_header{inv_duedate} =
243       qq|<th class=listheading>|
244     . $locale->text('Inv. Duedate')
245     . qq|</th>|;
246   $column_header{next_duedate} =
247       qq|<th class=listheading>|
248     . $locale->text('Dunning Duedate')
249     . qq|</th>|;
250   $column_header{invdate} =
251       qq|<th class=listheading>|
252     . $locale->text('Invdate')
253     . qq|</th>|;
254   $column_header{amount} =
255       qq|<th class=listheading>|
256     . $locale->text('Amount')
257     . qq|</th>|;
258   $column_header{fee} =
259       qq|<th class=listheading>|
260     . $locale->text('Total Fees')
261     . qq|</th>|;
262   $column_header{interest} =
263       qq|<th class=listheading>|
264     . $locale->text('Interest')
265     . qq|</th>|;
266
267   $form->header;
268
269
270   print qq|
271 <body>
272 <script type="text/javascript" src="js/common.js"></script>
273 <script type="text/javascript" src="js/dunning.js"></script>
274 <form name=Form method=post action=$form->{script}>
275
276
277 <table width=100%>
278   <tr>
279     <th class=listtop colspan=12>$form->{title}</th>
280   </tr>
281   <tr height="5"></tr>
282   <tr>|;
283   map { print "$column_header{$_}\n" if $column_header{$_}; } @column_index;
284
285   print qq|
286         </tr>
287 |;
288   my $i = 0;
289   foreach $ref (@{ $form->{DUNNINGS} }) {
290
291     $i++;
292     my $j = $i % 2;
293
294     print qq|
295         <tr valign=top class=listrow$j>
296 |;
297
298     $form->{selectdunning} =~ s/ selected//g;
299     if ($ref->{next_dunning_config_id} ne "") {
300       $form->{selectdunning} =~ s/value=$ref->{next_dunning_config_id}/value=$ref->{next_dunning_config_id} selected/;
301     }
302
303     $column_data{dunning_description} =
304       qq|<td>|
305       . qq|<input type=hidden name=inv_id_$i size=2 value="$ref->{id}">|
306       . qq|<input type=hidden name=customer_id_$i size=2 value="$ref->{customer_id}">|
307       . ($ref->{dunning_level} ? $ref->{dunning_level} : "&nbsp;")
308       . qq|</td>|;
309     $column_data{dunning_description_next} =
310       qq|<td>|
311       . qq|<select name=next_dunning_config_id_$i>$form->{selectdunning}</select>|
312       . qq|</td>|;
313     my $active = ($ref->{active}) ? "checked" : "";
314     $column_data{active} =
315       qq|<td><input type=checkbox name=active_$i value=1 $active></td>|;
316     my $email = ($ref->{email}) ? "checked" : "";
317     $column_data{email} =
318       qq|<td><input type=checkbox name=email_$i value=1 $email></td>|;
319     $column_data{next_duedate}           = qq|<td>$ref->{next_duedate}</td>|;
320
321     $column_data{inv_duedate}           = qq|<td><input type=hidden name=inv_duedate_$i size=6 value="$ref->{duedate}">$ref->{duedate}</td>|;
322     $column_data{invdate}           = qq|<td><input type=hidden name=invdate_$i size=6 value="$ref->{transdate}">$ref->{transdate}</td>|;
323     $column_data{invnumber}           = qq|<td><input type=hidden name=invnumber_$i size=6 value="$ref->{invnumber}">$ref->{invnumber}</td>|;
324     $column_data{customername}           = qq|<td><input type=hidden name=customername_$i size=6 value="$ref->{customername}">$ref->{customername}</td>|;
325
326     map { $column_data{$_} =
327             qq|<td align="right">|
328             . H($form->format_amount(\%myconfig, $ref->{$_} * 1, -2))
329             . qq|</td>|
330     } qw(amount fee interest);
331
332     map { print "$column_data{$_}\n" } @column_index;
333
334     print qq|
335         </tr>
336 |;
337   }
338
339   $form->{rowcount} = $i;
340
341   print qq|
342       </table>
343     </td>
344   </tr>
345   <tr>
346   <td><hr size=3 noshade></td>
347   </tr>
348 </table>|;
349   print_options();
350   print qq|
351 <br>
352 <form method=post action=$form->{script}>
353
354 <input name=callback type=hidden value="$form->{callback}">
355 <input name=rowcount type=hidden value="$form->{rowcount}">
356 <input name=nextsub type=hidden value="$form->{nextsub}">
357 <input name=groupinvoices type=hidden value="$form->{groupinvoices}">
358
359
360 <input type=hidden name=login value=$form->{login}>
361 <input type=hidden name=password value=$form->{password}>
362 <input type="hidden" name="action">
363 <input type="submit" name="dummy" value="|
364     . $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()">
365
366   </form>
367
368   </body>
369   </html>
370 |;
371
372
373   $lxdebug->leave_sub();
374
375 }
376
377 sub save {
378   $lxdebug->enter_sub();
379
380   for my $i (1 .. $form->{rowcount}) {
381     if ($form->{"dunning_description_$i"} ne "") {
382       $form->isblank("dunning_level_$i", $locale->text('Dunning Level missing in row '). $i);
383       $form->isblank("dunning_description_$i", $locale->text('Dunning Description missing in row '). $i);
384       $form->isblank("terms_$i", $locale->text('Terms missing in row '). $i);
385       $form->isblank("payment_terms_$i", $locale->text('Payment Terms missing in row '). $i);
386     }
387   }
388
389   DN->save_config(\%myconfig, \%$form);
390   # saving the history
391   if(!exists $form->{addition} && $form->{id} ne "") {
392         $form->{snumbers} = qq|dunning_id_| . $form->{"dunning_id"};
393     $form->{addition} = "SAVED FOR DUNNING";
394         $form->save_history($form->dbconnect(\%myconfig));
395   }
396   # /saving the history 
397   $form->redirect($locale->text('Dunning Process Config saved!'));
398
399   $lxdebug->leave_sub();
400 }
401
402 sub save_dunning {
403   $lxdebug->enter_sub();
404
405   my $active=1;
406   my @rows = ();
407   undef($form->{DUNNING_PDFS});
408
409   if ($form->{groupinvoices}) {
410     my %dunnings_for;
411
412     for my $i (1 .. $form->{rowcount}) {
413       next unless ($form->{"active_$i"});
414
415       $dunnings_for{$form->{"customer_id_$i"}} ||= {};
416       my $dunning_levels = $dunnings_for{$form->{"customer_id_$i"}};
417
418       $dunning_levels->{$form->{"next_dunning_config_id_$i"}} ||= [];
419       my $level = $dunning_levels->{$form->{"next_dunning_config_id_$i"}};
420
421       push @{ $level }, { "row"                    => $i,
422                           "invoice_id"             => $form->{"inv_id_$i"},
423                           "customer_id"            => $form->{"customer_id_$i"},
424                           "next_dunning_config_id" => $form->{"next_dunning_config_id_$i"},
425                           "email"                  => $form->{"email_$i"}, };
426     }
427
428     foreach my $levels (values %dunnings_for) {
429       foreach my $level (values %{ $levels }) {
430         next unless scalar @{ $level };
431
432         DN->save_dunning(\%myconfig, \%$form, $level, $userspath, $spool, $sendmail);
433       }
434     }
435
436   } else {
437     for my $i (1 .. $form->{rowcount}) {
438       next unless $form->{"active_$i"};
439
440       my $level = [ { "row"                    => $i,
441                       "invoice_id"             => $form->{"inv_id_$i"},
442                       "customer_id"            => $form->{"customer_id_$i"},
443                       "next_dunning_config_id" => $form->{"next_dunning_config_id_$i"},
444                       "email"                  => $form->{"email_$i"}, } ];
445       DN->save_dunning(\%myconfig, \%$form, $level, $userspath, $spool, $sendmail);
446     }
447   }
448
449   if($form->{DUNNING_PDFS}) {
450     DN->melt_pdfs(\%myconfig, \%$form,$spool);
451   }
452
453   # saving the history
454   if(!exists $form->{addition} && $form->{id} ne "") {
455         $form->{snumbers} = qq|dunning_id_| . $form->{"dunning_id"};
456     $form->{addition} = "DUNNING STARTED";
457         $form->save_history($form->dbconnect(\%myconfig));
458   }
459   # /saving the history
460
461   $form->redirect($locale->text('Dunning Process started for selected invoices!'));
462
463   $lxdebug->leave_sub();
464 }
465
466 sub set_email {
467   $lxdebug->enter_sub();
468
469
470   my $callback = "$form->{script}?action=set_email&";
471   map({ $callback .= "$_=" . $form->escape($form->{$_}) . "&" }
472       (qw(login password name input_subject input_body input_attachment email_subject email_body email_attachment), grep({ /^[fl]_/ } keys %$form)));
473
474   if ($form->{email_attachment}) {
475     $form->{email_attachment} = "checked";
476   }
477   $form->{"title"} = $locale->text("Set eMail text");
478   $form->header();
479   print($form->parse_html_template("dunning/set_email"));
480
481   $lxdebug->leave_sub();
482 }
483
484 sub search {
485   $lxdebug->enter_sub();
486   # setup customer selection
487   $form->all_vc(\%myconfig, "customer", "AR");
488
489   DN->get_config(\%myconfig, \%$form);
490
491   if (@{ $form->{all_customer} }) {
492     map { $customer .= "<option>$_->{name}--$_->{id}\n" }
493       @{ $form->{all_customer} };
494     $customer = qq|<select name=customer><option>\n$customer</select>|;
495   } else {
496     $customer = qq|<input name=customer size=35>|;
497   }
498
499   # dunning levels
500   if (@{ $form->{DUNNING} }) {
501     $form->{selectdunning_level} = "<option></option\n";
502     map {
503       $form->{selectdunning_level} .=
504         "<option value=$_->{id}>$_->{dunning_description}</option>\n"
505     } (@{ $form->{DUNNING} });
506   }
507   $dunning_level = qq| 
508     <tr> 
509     <th align=right nowrap>| . $locale->text('Next Dunning Level') . qq|</th>
510     <td colspan=3><select name=dunning_level>$form->{selectdunning_level}</select></td>
511     </tr>
512     | if $form->{selectdunning_level};
513
514   # departments
515   if (@{ $form->{all_departments} }) {
516     $form->{selectdepartment} = "<option>\n";
517     map {
518       $form->{selectdepartment} .=
519         "<option>$_->{description}--$_->{id}\n"
520     } (@{ $form->{all_departments} });
521   }
522   $department = qq| 
523     <tr> 
524     <th align=right nowrap>| . $locale->text('Department') . qq|</th>
525     <td colspan=3><select name=department>$form->{selectdepartment}</select></td>
526     </tr>
527     | if $form->{selectdepartment};
528   $form->{title}   = $locale->text('Search Dunning');
529   $form->{nextsub} = "show_dunning";
530
531   # use JavaScript Calendar or not
532   $form->{jsscript} = $jscalendar;
533   $jsscript = "";
534   if ($form->{jsscript}) {
535
536     # with JavaScript Calendar
537     $button1 = qq|
538       <td><input name=transdatefrom id=transdatefrom size=11 title="$myconfig{dateformat}" onBlur=\"check_right_date_format(this)\">
539       <input type=button name=transdatefrom id="trigger1" value=|
540       . $locale->text('button') . qq|></td>
541       |;
542     $button2 = qq|
543       <td><input name=transdateto id=transdateto size=11 title="$myconfig{dateformat}" onBlur=\"check_right_date_format(this)\">
544       <input type=button name=transdateto id="trigger2" value=|
545       . $locale->text('button') . qq|></td>
546       |;
547     $button3 = qq|
548       <td><input name=dunningfrom id=dunningfrom size=11 title="$myconfig{dateformat}" onBlur=\"check_right_date_format(this)\">
549       <input type=button name=dunningfrom id="trigger3" value=|
550       . $locale->text('button') . qq|></td>
551       |;
552     $button4 = qq|
553       <td><input name=dunningto id=dunningto size=11 title="$myconfig{dateformat}" onBlur=\"check_right_date_format(this)\">
554       <input type=button name=dunningto id="trigger4" value=|
555       . $locale->text('button') . qq|></td>
556       |;
557
558     #write Trigger
559     $jsscript =
560       Form->write_trigger(\%myconfig, "4", "transdatefrom", "BR", "trigger1", "transdateto", "BR", "trigger2", "dunningfrom", "BR", "trigger3", "dunningto", "BR", "trigger4");
561   } else {
562
563     # without JavaScript Calendar
564     $button1 =
565       qq|<td><input name=transdatefrom id=transdatefrom size=11 title="$myconfig{dateformat}" onBlur=\"check_right_date_format(this)\"></td>|;
566     $button2 =
567       qq|<td><input name=transdateto id=transdateto size=11 title="$myconfig{dateformat}" onBlur=\"check_right_date_format(this)\"></td>|;
568     $button3 =
569       qq|<td><input name=dunningfrom id=dunningfrom size=11 title="$myconfig{dateformat}" onBlur=\"check_right_date_format(this)\"></td>|;
570     $button4 =
571       qq|<td><input name=dunningfrom id=dunningto size=11 title="$myconfig{dateformat}" onBlur=\"check_right_date_format(this)\"></td>|;
572   }
573
574   $form->{fokus} = "search.customer";
575   $form->{javascript} .= qq|<script type="text/javascript" src="js/common.js"></script>|;
576   $form->header;
577   $onload = qq|focus()|;
578   $onload .= qq|;setupDateFormat('|. $myconfig{dateformat} .qq|', '|. $locale->text("Falsches Datumsformat!") .qq|')|;
579   $onload .= qq|;setupPoints('|. $myconfig{numberformat} .qq|', '|. $locale->text("wrongformat") .qq|')|;
580
581   print qq|
582 <body onLoad="$onload">
583
584 <form method=post name="search" action=$form->{script}>
585
586 <table width=100%>
587   <tr><th class=listtop>$form->{title}</th></tr>
588   <tr height="5"></tr>
589   <tr>
590     <td>
591       <table>
592         <tr>
593           <th align=right>| . $locale->text('Customer') . qq|</th>
594           <td colspan=3>$customer</td>
595         </tr>
596         $dunning_level
597         $department
598         <tr>
599           <th align=right nowrap>| . $locale->text('Invoice Number') . qq|</th>
600           <td colspan=3><input name=invnumber size=20></td>
601         </tr>
602         <tr>
603           <th align=right nowrap>| . $locale->text('Order Number') . qq|</th>
604           <td colspan=3><input name=ordnumber size=20></td>
605         </tr>
606         <tr>
607           <th align=right nowrap>| . $locale->text('Notes') . qq|</th>
608           <td colspan=3><input name=notes size=40></td>
609         </tr>
610         <tr>
611           <th align=right nowrap>| . $locale->text('Invdate from') . qq|</th>
612           $button1
613           <th align=right nowrap>| . $locale->text('To') . qq|</th>
614           $button2
615         </tr>
616         <tr>
617           <th align=right nowrap>| . $locale->text('Dunning Date from') . qq|</th>
618           $button3
619           <th align=right nowrap>| . $locale->text('To') . qq|</th>
620           $button4
621         </tr>
622
623       </table>
624     </td>
625   </tr>
626   <tr>
627     <td><hr size=3 noshade></td>
628   </tr>
629   <tr>
630     <td>
631       <table>
632         <tr>
633           <th align=right nowrap>| . $locale->text('Show old dunnings') . qq|</th>
634           <td><input type=checkbox value=1 name=showold></td>
635         </tr>
636       </table>
637     </td>
638   </tr>
639 </table>
640
641 <input type=hidden name=nextsub value=$form->{nextsub}>
642
643 <input type=hidden name=login value=$form->{login}>
644 <input type=hidden name=password value=$form->{password}>
645
646 <br>
647 <input class=submit type=submit name=action value="|
648     . $locale->text('Continue') . qq|">
649
650 </form>
651
652 </body>
653
654 $jsscript
655
656 </html>
657 |;
658
659   $lxdebug->leave_sub();
660
661 }
662
663 sub show_dunning {
664   $lxdebug->enter_sub();
665
666   DN->get_dunning(\%myconfig, \%$form);
667   $form->{title} = $locale->text('Dunning overview');
668
669
670
671
672   
673   $form->{callback} =
674     "$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}&notes=$form->{notes}&showold=$form->{showold}&dunning_level=$form->{dunning_level}"
675     unless $form->{callback};
676
677   @column_index = qw(dunning_description customername invnumber invdate inv_duedate invamount dunning_date next_duedate fee interest );
678
679   $column_header{dunning_description} =
680       qq|<th class=listheading>|
681     . $locale->text('Dunning Level')
682     . qq|</th>|;
683   $column_header{customername} =
684       qq|<th class=listheading>|
685     . $locale->text('Customername')
686     . qq|</th>|;
687   $column_header{invnumber} =
688       qq|<th class=listheading>|
689     . $locale->text('Invnumber')
690     . qq|</th>|;
691   $column_header{inv_duedate} =
692       qq|<th class=listheading>|
693     . $locale->text('Invoice Duedate')
694     . qq|</th>|;
695   $column_header{dunning_date} =
696       qq|<th class=listheading>|
697     . $locale->text('Dunning Date')
698     . qq|</th>|;
699   $column_header{next_duedate} =
700       qq|<th class=listheading>|
701     . $locale->text('Dunning Duedate')
702     . qq|</th>|;
703   $column_header{invdate} =
704       qq|<th class=listheading>|
705     . $locale->text('Invdate')
706     . qq|</th>|;
707   $column_header{invamount} =
708       qq|<th class=listheading>|
709     . $locale->text('Amount')
710     . qq|</th>|;
711   $column_header{fee} =
712       qq|<th class=listheading>|
713     . $locale->text('Total Fees')
714     . qq|</th>|;
715   $column_header{interest} =
716       qq|<th class=listheading>|
717     . $locale->text('Interest')
718     . qq|</th>|;
719
720   $form->header;
721
722
723   print qq|
724 <body>
725 <script type="text/javascript" src="js/common.js"></script>
726 <script type="text/javascript" src="js/dunning.js"></script>
727 <form method=post action=$form->{script}>
728
729
730 <table width=100%>
731   <tr>
732     <th class=listtop colspan=10>$form->{title}</th>
733   </tr>
734   <tr height="5"></tr>
735   <tr>|;
736   map { print "$column_header{$_}\n" } @column_index;
737
738   print qq|
739         </tr>
740 |;
741
742   my %columns = (
743     "dunning_duedate" => "next_duedate",
744     "duedate" => "inv_duedate",
745     "transdate" => "invdate",
746     "amount" => "invamount",
747     );
748
749   my $i = 0;
750   my $j = 0;
751   my ($previous_dunning_id, $first_row_for_dunning);
752   foreach $ref (@{ $form->{DUNNINGS} }) {
753     $i++;
754
755     if ($previous_dunning_id != $ref->{dunning_id}) {
756       $j++;
757       $j = $j % 2;
758       $first_row_for_dunning = 1;
759     } else {
760       $first_row_for_dunning = 0;
761     }
762     $previous_dunning_id = $ref->{dunning_id};
763
764     print qq|
765         <tr valign=top class=listrow$j>
766 |;
767
768   
769
770     foreach (qw(dunning_date dunning_duedate duedate transdate customername amount fee interest)) {
771       my $col = $columns{$_} ? $columns{$_} : $_;
772       $column_data{$col} = "<td>" . H($ref->{$_}) . "</td>";
773     }
774
775     if ($first_row_for_dunning) {
776       $column_data{dunning_description} =
777         qq|<td><a href="dn.pl?action=print_dunning&format=pdf&media=screen&| .
778         qq|dunning_id=| . E($ref->{dunning_id}) .
779         join("", map({ "&${_}=" . E($form->{$_}) } qw(login password callback))) .
780         qq|">| . H($ref->{dunning_description}) . qq|</a></td>|;
781     } else {
782       $column_data{dunning_description} = qq|<td>&nbsp;</td>|;
783       $column_data{customername} = qq|<td>&nbsp;</td>|;
784     }
785
786     $column_data{invnumber} =
787       qq|<td><a href="| . ($ref->{invoice} ? "is.pl" : "ar.pl" ) .
788       qq|?action=edit&id=| . H($ref->{id}) .
789       join("", map({ "&${_}=" . E($form->{$_}) } qw(login password callback))) .
790       qq|">| . H($ref->{invnumber}) . qq|</a></td>|;
791
792     map { print "$column_data{$_}\n" } @column_index;
793
794     print qq|
795         </tr>
796 |;
797   }
798
799   $form->{rowcount} = $i;
800
801   print qq|
802       </table>
803     </td>
804   </tr>
805   <tr>
806   <td><hr size=3 noshade></td>
807   </tr>
808 </table>
809
810 <br>
811 <form method=post action=$form->{script}>
812
813 <input name=callback type=hidden value="$form->{callback}">
814 <input name=rowcount type=hidden value="$form->{rowcount}">
815 <input name=nextsub type=hidden value="$form->{nextsub}">
816
817
818 <input type=hidden name=login value=$form->{login}>
819 <input type=hidden name=password value=$form->{password}>
820
821   </form>
822
823   </body>
824   </html>
825 |;
826
827
828   $lxdebug->leave_sub();
829
830 }
831
832 sub print_dunning {
833   $lxdebug->enter_sub();
834
835   DN->print_dunning(\%myconfig, \%$form, $form->{dunning_id}, $userspath, $spool, $sendmail);
836
837   if($form->{DUNNING_PDFS}) {
838     DN->melt_pdfs(\%myconfig, \%$form,$spool);
839   } else {
840     $form->redirect($locale->text('Could not create dunning copy!'));
841   }
842
843   $lxdebug->leave_sub();
844
845 }
846
847 # end of main
848