]> wagnertech.de Git - kivitendo-erp.git/blob - bin/mozilla/dn.pl
Falscher Variablenname.
[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
64   # setup customer selection
65   $form->all_vc(\%myconfig, "customer", "AR");
66
67   DN->get_config(\%myconfig, \%$form);
68
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} };
72
73   $form->{title}    = $locale->text('Start Dunning Process');
74   $form->{jsscript} = 1;
75   $form->{fokus}    = "search.customer";
76   $form->header();
77
78   print $form->parse_html_template("dunning/add");
79
80   $lxdebug->leave_sub();
81 }
82
83 sub show_invoices {
84   $lxdebug->enter_sub();
85
86   DN->get_invoices(\%myconfig, \%$form);
87   $form->{title} = $locale->text('Start Dunning Process');
88
89   if (@{ $form->{DUNNING_CONFIG} }) {
90     foreach $item (@{ $form->{DUNNING_CONFIG} }) {
91         $form->{selectdunning} .=
92           "<option value=$item->{id}>$item->{dunning_description}</option>";
93     }
94   }
95
96
97   $form->{nextsub} = "save_dunning";
98
99   $form->{jsscript} = 1;
100   $form->{javascript} .= qq|<script type="text/javascript" src="js/checkbox_utils.js"></script>|;
101
102   $form->{callback} =
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}&notes=$form->{notes}"
104     unless $form->{callback};
105
106   @column_index = qw(dunning_description dunning_description_next active email customername invnumber invdate inv_duedate amount next_duedate fee interest );
107
108   $column_header{dunning_description} =
109       qq|<th class="listheading" colspan="2">|
110     . $locale->text('Current / Next Level')
111     . qq|</th>|;
112   $column_header{active} =
113       qq|<th class=listheading>|
114     . NTI($cgi->checkbox('-name' => 'selectall_active',
115                          '-label' => $locale->text('Active?'),
116                          '-checked' => 0,
117                          '-onclick' => "checkbox_check_all('selectall_active', 'active_', 1, " . scalar(@{ $form->{DUNNINGS} }) . ")"))
118     . qq|</th>|;
119   $column_header{email} =
120       qq|<th class=listheading>|
121     . NTI($cgi->checkbox('-name' => 'selectall_email',
122                          '-label' => $locale->text('eMail?'),
123                          '-checked' => 0,
124                          '-onclick' => "checkbox_check_all('selectall_email', 'email_', 1, " . scalar(@{ $form->{DUNNINGS} }) . ")"))
125     . qq|</th>|;
126   $column_header{customername} =
127       qq|<th class=listheading>|
128     . $locale->text('Customername')
129     . qq|</th>|;
130   $column_header{invnumber} =
131       qq|<th class=listheading>|
132     . $locale->text('Invno.')
133     . qq|</th>|;
134   $column_header{inv_duedate} =
135       qq|<th class=listheading>|
136     . $locale->text('Inv. Duedate')
137     . qq|</th>|;
138   $column_header{next_duedate} =
139       qq|<th class=listheading>|
140     . $locale->text('Dunning Duedate')
141     . qq|</th>|;
142   $column_header{invdate} =
143       qq|<th class=listheading>|
144     . $locale->text('Invdate')
145     . qq|</th>|;
146   $column_header{amount} =
147       qq|<th class=listheading>|
148     . $locale->text('Amount')
149     . qq|</th>|;
150   $column_header{fee} =
151       qq|<th class=listheading>|
152     . $locale->text('Total Fees')
153     . qq|</th>|;
154   $column_header{interest} =
155       qq|<th class=listheading>|
156     . $locale->text('Interest')
157     . qq|</th>|;
158
159   $form->header;
160
161
162   print qq|
163 <body>
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}>
167
168
169 <table width=100%>
170   <tr>
171     <th class=listtop colspan=12>$form->{title}</th>
172   </tr>
173   <tr height="5"></tr>
174   <tr>|;
175   map { print "$column_header{$_}\n" if $column_header{$_}; } @column_index;
176
177   print qq|
178         </tr>
179 |;
180   my $i = 0;
181   foreach $ref (@{ $form->{DUNNINGS} }) {
182
183     $i++;
184     my $j = $i % 2;
185
186     print qq|
187         <tr valign=top class=listrow$j>
188 |;
189
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/;
193     }
194
195     $column_data{dunning_description} =
196       qq|<td>|
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} : "&nbsp;")
200       . qq|</td>|;
201     $column_data{dunning_description_next} =
202       qq|<td>|
203       . qq|<select name=next_dunning_config_id_$i>$form->{selectdunning}</select>|
204       . qq|</td>|;
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>|;
212
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>|;
217
218     map { $column_data{$_} =
219             qq|<td align="right">|
220             . H($form->format_amount(\%myconfig, $ref->{$_} * 1, -2))
221             . qq|</td>|
222     } qw(amount fee interest);
223
224     map { print "$column_data{$_}\n" } @column_index;
225
226     print qq|
227         </tr>
228 |;
229   }
230
231   $form->{rowcount} = $i;
232
233   print qq|
234       </table>
235     </td>
236   </tr>
237   <tr>
238   <td><hr size=3 noshade></td>
239   </tr>
240 </table>|;
241   print_options();
242   print qq|
243 <br>
244 <form method=post action=$form->{script}>
245
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}">
250
251
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()">
257
258   </form>
259
260   </body>
261   </html>
262 |;
263
264
265   $lxdebug->leave_sub();
266
267 }
268
269 sub save {
270   $lxdebug->enter_sub();
271
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);
278     }
279   }
280
281   DN->save_config(\%myconfig, \%$form);
282   # saving the history
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));
287   }
288   # /saving the history 
289   $form->redirect($locale->text('Dunning Process Config saved!'));
290
291   $lxdebug->leave_sub();
292 }
293
294 sub save_dunning {
295   $lxdebug->enter_sub();
296
297   my $active=1;
298   my @rows = ();
299   undef($form->{DUNNING_PDFS});
300
301   if ($form->{groupinvoices}) {
302     my %dunnings_for;
303
304     for my $i (1 .. $form->{rowcount}) {
305       next unless ($form->{"active_$i"});
306
307       $dunnings_for{$form->{"customer_id_$i"}} ||= {};
308       my $dunning_levels = $dunnings_for{$form->{"customer_id_$i"}};
309
310       $dunning_levels->{$form->{"next_dunning_config_id_$i"}} ||= [];
311       my $level = $dunning_levels->{$form->{"next_dunning_config_id_$i"}};
312
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"}, };
318     }
319
320     foreach my $levels (values %dunnings_for) {
321       foreach my $level (values %{ $levels }) {
322         next unless scalar @{ $level };
323
324         DN->save_dunning(\%myconfig, \%$form, $level, $userspath, $spool, $sendmail);
325       }
326     }
327
328   } else {
329     for my $i (1 .. $form->{rowcount}) {
330       next unless $form->{"active_$i"};
331
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);
338     }
339   }
340
341   if($form->{DUNNING_PDFS}) {
342     DN->melt_pdfs(\%myconfig, \%$form,$spool);
343   }
344
345   # saving the history
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));
350   }
351   # /saving the history
352
353   $form->redirect($locale->text('Dunning Process started for selected invoices!'));
354
355   $lxdebug->leave_sub();
356 }
357
358 sub set_email {
359   $lxdebug->enter_sub();
360
361
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)));
365
366   if ($form->{email_attachment}) {
367     $form->{email_attachment} = "checked";
368   }
369   $form->{"title"} = $locale->text("Set eMail text");
370   $form->header();
371   print($form->parse_html_template("dunning/set_email"));
372
373   $lxdebug->leave_sub();
374 }
375
376 sub search {
377   $lxdebug->enter_sub();
378   # setup customer selection
379   $form->all_vc(\%myconfig, "customer", "AR");
380
381   DN->get_config(\%myconfig, \%$form);
382
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>|;
387   } else {
388     $customer = qq|<input name=customer size=35>|;
389   }
390
391   # dunning levels
392   if (@{ $form->{DUNNING} }) {
393     $form->{selectdunning_level} = "<option></option\n";
394     map {
395       $form->{selectdunning_level} .=
396         "<option value=$_->{id}>$_->{dunning_description}</option>\n"
397     } (@{ $form->{DUNNING} });
398   }
399   $dunning_level = qq| 
400     <tr> 
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>
403     </tr>
404     | if $form->{selectdunning_level};
405
406   # departments
407   if (@{ $form->{all_departments} }) {
408     $form->{selectdepartment} = "<option>\n";
409     map {
410       $form->{selectdepartment} .=
411         "<option>$_->{description}--$_->{id}\n"
412     } (@{ $form->{all_departments} });
413   }
414   $department = qq| 
415     <tr> 
416     <th align=right nowrap>| . $locale->text('Department') . qq|</th>
417     <td colspan=3><select name=department>$form->{selectdepartment}</select></td>
418     </tr>
419     | if $form->{selectdepartment};
420   $form->{title}   = $locale->text('Search Dunning');
421   $form->{nextsub} = "show_dunning";
422
423   # use JavaScript Calendar or not
424   $form->{jsscript} = $jscalendar;
425   $jsscript = "";
426   if ($form->{jsscript}) {
427
428     # with JavaScript Calendar
429     $button1 = qq|
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>
433       |;
434     $button2 = qq|
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>
438       |;
439     $button3 = qq|
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>
443       |;
444     $button4 = qq|
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>
448       |;
449
450     #write Trigger
451     $jsscript =
452       Form->write_trigger(\%myconfig, "4", "transdatefrom", "BR", "trigger1", "transdateto", "BR", "trigger2", "dunningfrom", "BR", "trigger3", "dunningto", "BR", "trigger4");
453   } else {
454
455     # without JavaScript Calendar
456     $button1 =
457       qq|<td><input name=transdatefrom id=transdatefrom size=11 title="$myconfig{dateformat}" onBlur=\"check_right_date_format(this)\"></td>|;
458     $button2 =
459       qq|<td><input name=transdateto id=transdateto size=11 title="$myconfig{dateformat}" onBlur=\"check_right_date_format(this)\"></td>|;
460     $button3 =
461       qq|<td><input name=dunningfrom id=dunningfrom size=11 title="$myconfig{dateformat}" onBlur=\"check_right_date_format(this)\"></td>|;
462     $button4 =
463       qq|<td><input name=dunningfrom id=dunningto size=11 title="$myconfig{dateformat}" onBlur=\"check_right_date_format(this)\"></td>|;
464   }
465
466   $form->{fokus} = "search.customer";
467   $form->{javascript} .= qq|<script type="text/javascript" src="js/common.js"></script>|;
468   $form->header;
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|')|;
472
473   print qq|
474 <body onLoad="$onload">
475
476 <form method=post name="search" action=$form->{script}>
477
478 <table width=100%>
479   <tr><th class=listtop>$form->{title}</th></tr>
480   <tr height="5"></tr>
481   <tr>
482     <td>
483       <table>
484         <tr>
485           <th align=right>| . $locale->text('Customer') . qq|</th>
486           <td colspan=3>$customer</td>
487         </tr>
488         $dunning_level
489         $department
490         <tr>
491           <th align=right nowrap>| . $locale->text('Invoice Number') . qq|</th>
492           <td colspan=3><input name=invnumber size=20></td>
493         </tr>
494         <tr>
495           <th align=right nowrap>| . $locale->text('Order Number') . qq|</th>
496           <td colspan=3><input name=ordnumber size=20></td>
497         </tr>
498         <tr>
499           <th align=right nowrap>| . $locale->text('Notes') . qq|</th>
500           <td colspan=3><input name=notes size=40></td>
501         </tr>
502         <tr>
503           <th align=right nowrap>| . $locale->text('Invdate from') . qq|</th>
504           $button1
505           <th align=right nowrap>| . $locale->text('To') . qq|</th>
506           $button2
507         </tr>
508         <tr>
509           <th align=right nowrap>| . $locale->text('Dunning Date from') . qq|</th>
510           $button3
511           <th align=right nowrap>| . $locale->text('To') . qq|</th>
512           $button4
513         </tr>
514
515       </table>
516     </td>
517   </tr>
518   <tr>
519     <td><hr size=3 noshade></td>
520   </tr>
521   <tr>
522     <td>
523       <table>
524         <tr>
525           <th align=right nowrap>| . $locale->text('Show old dunnings') . qq|</th>
526           <td><input type=checkbox value=1 name=showold></td>
527         </tr>
528       </table>
529     </td>
530   </tr>
531 </table>
532
533 <input type=hidden name=nextsub value=$form->{nextsub}>
534
535 <input type=hidden name=login value=$form->{login}>
536 <input type=hidden name=password value=$form->{password}>
537
538 <br>
539 <input class=submit type=submit name=action value="|
540     . $locale->text('Continue') . qq|">
541
542 </form>
543
544 </body>
545
546 $jsscript
547
548 </html>
549 |;
550
551   $lxdebug->leave_sub();
552
553 }
554
555 sub show_dunning {
556   $lxdebug->enter_sub();
557
558   DN->get_dunning(\%myconfig, \%$form);
559   $form->{title} = $locale->text('Dunning overview');
560
561
562
563
564   
565   $form->{callback} =
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}&notes=$form->{notes}&showold=$form->{showold}&dunning_level=$form->{dunning_level}"
567     unless $form->{callback};
568
569   @column_index = qw(dunning_description customername invnumber invdate inv_duedate invamount dunning_date next_duedate fee interest );
570
571   $column_header{dunning_description} =
572       qq|<th class=listheading>|
573     . $locale->text('Dunning Level')
574     . qq|</th>|;
575   $column_header{customername} =
576       qq|<th class=listheading>|
577     . $locale->text('Customername')
578     . qq|</th>|;
579   $column_header{invnumber} =
580       qq|<th class=listheading>|
581     . $locale->text('Invnumber')
582     . qq|</th>|;
583   $column_header{inv_duedate} =
584       qq|<th class=listheading>|
585     . $locale->text('Invoice Duedate')
586     . qq|</th>|;
587   $column_header{dunning_date} =
588       qq|<th class=listheading>|
589     . $locale->text('Dunning Date')
590     . qq|</th>|;
591   $column_header{next_duedate} =
592       qq|<th class=listheading>|
593     . $locale->text('Dunning Duedate')
594     . qq|</th>|;
595   $column_header{invdate} =
596       qq|<th class=listheading>|
597     . $locale->text('Invdate')
598     . qq|</th>|;
599   $column_header{invamount} =
600       qq|<th class=listheading>|
601     . $locale->text('Amount')
602     . qq|</th>|;
603   $column_header{fee} =
604       qq|<th class=listheading>|
605     . $locale->text('Total Fees')
606     . qq|</th>|;
607   $column_header{interest} =
608       qq|<th class=listheading>|
609     . $locale->text('Interest')
610     . qq|</th>|;
611
612   $form->header;
613
614
615   print qq|
616 <body>
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}>
620
621
622 <table width=100%>
623   <tr>
624     <th class=listtop colspan=10>$form->{title}</th>
625   </tr>
626   <tr height="5"></tr>
627   <tr>|;
628   map { print "$column_header{$_}\n" } @column_index;
629
630   print qq|
631         </tr>
632 |;
633
634   my %columns = (
635     "dunning_duedate" => "next_duedate",
636     "duedate" => "inv_duedate",
637     "transdate" => "invdate",
638     "amount" => "invamount",
639     );
640
641   my $i = 0;
642   my $j = 0;
643   my ($previous_dunning_id, $first_row_for_dunning);
644   foreach $ref (@{ $form->{DUNNINGS} }) {
645     $i++;
646
647     if ($previous_dunning_id != $ref->{dunning_id}) {
648       $j++;
649       $j = $j % 2;
650       $first_row_for_dunning = 1;
651     } else {
652       $first_row_for_dunning = 0;
653     }
654     $previous_dunning_id = $ref->{dunning_id};
655
656     print qq|
657         <tr valign=top class=listrow$j>
658 |;
659
660   
661
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>";
665     }
666
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>|;
673     } else {
674       $column_data{dunning_description} = qq|<td>&nbsp;</td>|;
675       $column_data{customername} = qq|<td>&nbsp;</td>|;
676     }
677
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>|;
683
684     map { print "$column_data{$_}\n" } @column_index;
685
686     print qq|
687         </tr>
688 |;
689   }
690
691   $form->{rowcount} = $i;
692
693   print qq|
694       </table>
695     </td>
696   </tr>
697   <tr>
698   <td><hr size=3 noshade></td>
699   </tr>
700 </table>
701
702 <br>
703 <form method=post action=$form->{script}>
704
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}">
708
709
710 <input type=hidden name=login value=$form->{login}>
711 <input type=hidden name=password value=$form->{password}>
712
713   </form>
714
715   </body>
716   </html>
717 |;
718
719
720   $lxdebug->leave_sub();
721
722 }
723
724 sub print_dunning {
725   $lxdebug->enter_sub();
726
727   DN->print_dunning(\%myconfig, \%$form, $form->{dunning_id}, $userspath, $spool, $sendmail);
728
729   if($form->{DUNNING_PDFS}) {
730     DN->melt_pdfs(\%myconfig, \%$form,$spool);
731   } else {
732     $form->redirect($locale->text('Could not create dunning copy!'));
733   }
734
735   $lxdebug->leave_sub();
736
737 }
738
739 # end of main
740