Button in der Mahnansicht deaktivieren nach Start des Mahnprozess
[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 "$form->{path}/io.pl";
40 require "$form->{path}/arap.pl";
41
42 1;
43
44 sub edit_config {
45   $lxdebug->enter_sub();
46
47   # edit all dunning config data
48
49   $form->header;
50   DN->get_config(\%myconfig, \%$form);
51   $form->{title} = $locale->text('Edit Dunning Process Config');
52   
53   $form->{callback} =
54     "$form->{script}?action=edit_config&path=$form->{path}&login=$form->{login}&password=$form->{password}"
55     unless $form->{callback};
56
57   @column_index = qw(dunning_level dunning_description active auto email payment_terms terms fee interest template);
58
59   $column_header{dunning_level} =
60       qq|<th class=listheading>|
61     . $locale->text('Dunning Level')
62     . qq|</th>|;
63   $column_header{dunning_description} =
64       qq|<th class=listheading>|
65     . $locale->text('Dunning Description')
66     . qq|</th>|;
67   $column_header{active} =
68       qq|<th class=listheading>|
69     . $locale->text('Active?')
70     . qq|</th>|;
71   $column_header{auto} =
72       qq|<th class=listheading>|
73     . $locale->text('Auto Send?')
74     . qq|</th>|;
75   $column_header{email} =
76       qq|<th class=listheading>|
77     . $locale->text('eMail Send?')
78     . qq|</th>|;
79   $column_header{payment_terms} =
80       qq|<th class=listheading>|
81     . $locale->text('Fristsetzung')
82     . qq|</th>|;
83   $column_header{terms} =
84       qq|<th class=listheading>|
85     . $locale->text('Duedate +Days')
86     . qq|</th>|;
87   $column_header{fee} =
88       qq|<th class=listheading>|
89     . $locale->text('Fee')
90     . qq|</th>|;
91   $column_header{interest} =
92       qq|<th class=listheading>|
93     . $locale->text('Interest Rate')
94     . qq|</th>|;
95   $column_header{template} =
96       qq|<th class=listheading>|
97     . $locale->text('Template')
98     . qq|</th>|;
99   print qq|
100 <body>
101 <script type="text/javascript" src="js/common.js"></script>
102 <script type="text/javascript" src="js/dunning.js"></script>
103 <form method=post action=$form->{script}>
104
105
106 <table width=100%>
107   <tr>
108     <th class=listtop colspan=9>$form->{title}</th>
109   </tr>
110   <tr height="5"></tr>
111   <tr>|;
112   map { print "$column_header{$_}\n" } @column_index;
113
114   print qq|
115         </tr>
116 |;
117   my $i = 0;
118   foreach $ref (@{ $form->{DUNNING} }) {
119
120     $i++;
121     my $j = $i % 2;
122
123     print qq|
124         <tr valign=top class=listrow$j>
125 |;
126
127
128     $column_data{dunning_level} =
129       qq|<td><input type=hidden name=dunning_level_$i size=2 value="$i"><input type=hidden name=id_$i value="$ref->{id}">$i</td>|;
130     $column_data{dunning_description}           = qq|<td><input name=dunning_description_$i value="$ref->{dunning_description}"></td>|;
131     my $active = ($ref->{active}) ? "checked" : "";
132     $column_data{active} =
133       qq|<td><input type=checkbox name=active_$i value=1 $active></td>|;
134     my $email = ($ref->{email}) ? "checked" : "";
135   $column_data{email} =
136     qq|<td><input type=checkbox name=email_$i value=1 $email><button type="button" onclick="set_email_window('email_subject_$i', 'email_body_$i', 'email_attachment_$i')">| . $locale->text('L') . qq|</button><input type=hidden name=email_body_$i value="$ref->{email_body}"><input type=hidden name=email_subject_$i value="$ref->{email_subject}"><input type=hidden name=email_attachment_$i value="$ref->{email_attachment}"></td>|;
137
138     my $auto = ($ref->{auto}) ? "checked" : "";
139     $column_data{auto} =
140       qq|<td><input type=checkbox name=auto_$i value=1 $auto></td>|;
141     $column_data{payment_terms}           = qq|<td><input name=payment_terms_$i size=3 value="$ref->{payment_terms}"></td>|;
142     $column_data{terms}           = qq|<td><input name=terms_$i size=3 value="$ref->{terms}"></td>|;
143     $column_data{fee}           = qq|<td><input name=fee_$i size=5 value="$ref->{fee}"></td>|;
144     $column_data{interest}           = qq|<td><input name=interest_$i size=4 value="$ref->{interest}">%</td>|;
145     $column_data{template}           = qq|<td><input name=template_$i value="$ref->{template}"></td>|;
146
147
148
149     map { print "$column_data{$_}\n" } @column_index;
150
151     print qq|
152         </tr>
153 |;
154   }
155   $i++;
156   my $j = $i % 2;
157
158   print qq|
159         <tr valign=top class=listrow$j>
160 |;
161
162
163   $column_data{dunning_level} =
164     qq|<td><input type=hidden size=2 name=dunning_level_$i value=$i>$i</td>|;
165   $column_data{dunning_description}           = qq|<td><input name=dunning_description_$i ></td>|;
166   my $active = "";
167   $column_data{active} =
168     qq|<td><input type=checkbox name=active_$i value=1 $active></td>|;
169   my $email = "";
170   $column_data{email} =
171     qq|<td><input type=checkbox name=email_$i value=1 $email><button type="button" onclick="set_email_window('email_subject_$i', 'email_body_$i', 'email_attachment_$i')">| . $locale->text('L') . qq|</button><input type=hidden name=email_body_$i><input type=hidden name=email_subject_$i><input type=hidden name=email_attachment_$i></td>|;
172   my $auto = "";
173   $column_data{auto} =
174     qq|<td><input type=checkbox name=auto_$i value=1 $auto></td>|;
175   $column_data{payment_terms}           = qq|<td><input  size=3 name=payment_terms_$i></td>|;
176   $column_data{terms}           = qq|<td><input  size=3 name=terms_$i></td>|;
177   $column_data{fee}           = qq|<td><input  size=5 name=fee_$i></td>|;
178   $column_data{interest}           = qq|<td><input  size=4 name=interest_$i>%</td>|;
179   $column_data{template}           = qq|<td><input name=template_$i></td>|;
180
181
182   $form->{rowcount} = $i;
183   map { print "$column_data{$_}\n" } @column_index;
184
185   print qq|
186       </tr>
187 |;
188
189
190   print qq|
191       </table>
192     </td>
193   </tr>
194   <tr>
195   <td><hr size=3 noshade></td>
196   </tr>
197 </table>
198
199 <br>
200 <form method=post action=$form->{script}>
201
202 <input name=callback type=hidden value="$form->{callback}">
203 <input name=rowcount type=hidden value="$form->{rowcount}">
204
205 <input type=hidden name=path value=$form->{path}>
206 <input type=hidden name=login value=$form->{login}>
207 <input type=hidden name=password value=$form->{password}>
208
209 <input class=submit type=submit name=action value="|
210     . $locale->text('Save') . qq|">|;
211
212   if ($form->{menubar}) {
213     require "$form->{path}/menu.pl";
214     &menubar;
215   }
216
217   print qq|
218
219   </form>
220
221   </body>
222   </html>
223 |;
224
225   $lxdebug->leave_sub();
226 }
227
228 sub add {
229   $lxdebug->enter_sub();
230   # setup customer selection
231   $form->all_vc(\%myconfig, "customer", "AR");
232
233   DN->get_config(\%myconfig, \%$form);
234
235   if (@{ $form->{all_customer} }) {
236     map { $customer .= "<option>$_->{name}--$_->{id}\n" }
237       @{ $form->{all_customer} };
238     $customer = qq|<select name=customer><option>\n$customer</select>|;
239   } else {
240     $customer = qq|<input name=customer size=35>|;
241   }
242
243   # dunning levels
244   if (@{ $form->{DUNNING} }) {
245     $form->{selectdunning_level} = "<option></option\n";
246     map {
247       $form->{selectdunning_level} .=
248         "<option value=$_->{id}>$_->{dunning_description}</option>\n"
249     } (@{ $form->{DUNNING} });
250   }
251   $dunning_level = qq| 
252     <tr> 
253     <th align=right nowrap>| . $locale->text('Next Dunning Level') . qq|</th>
254     <td colspan=3><select name=dunning_level>$form->{selectdunning_level}</select></td>
255     </tr>
256     | if $form->{selectdunning_level};
257
258   # departments
259   if (@{ $form->{all_departments} }) {
260     $form->{selectdepartment} = "<option>\n";
261     map {
262       $form->{selectdepartment} .=
263         "<option>$_->{description}--$_->{id}\n"
264     } (@{ $form->{all_departments} });
265   }
266   $department = qq| 
267     <tr> 
268     <th align=right nowrap>| . $locale->text('Department') . qq|</th>
269     <td colspan=3><select name=department>$form->{selectdepartment}</select></td>
270     </tr>
271     | if $form->{selectdepartment};
272   $form->{title}   = $locale->text('Start Dunning Process');
273   $form->{nextsub} = "show_invoices";
274
275   # use JavaScript Calendar or not
276   $form->{jsscript} = $jscalendar;
277   $jsscript = "";
278   if ($form->{jsscript}) {
279
280     # with JavaScript Calendar
281     $button1 = qq|
282       <td><input name=paymentuntil id=paymentuntil size=11 title="$myconfig{dateformat}">
283       <input type=button name=paymentuntil id="trigger1" value=|
284       . $locale->text('button') . qq|></td>
285       |;
286
287     #write Trigger
288     $jsscript =
289       Form->write_trigger(\%myconfig, "1", "paymentuntil", "BR", "trigger1");
290   } else {
291
292     # without JavaScript Calendar
293     $button1 =
294       qq|<td><input name=paymentuntil id=paymentuntil size=11 title="$myconfig{dateformat}"></td>|;
295   }
296   $form->{fokus} = "search.customer";
297   $form->header;
298   print qq|
299 <body onLoad="fokus()">
300
301 <form method=post name="search" action=$form->{script}>
302
303 <table width=100%>
304   <tr><th class=listtop>$form->{title}</th></tr>
305   <tr height="5"></tr>
306   <tr>
307     <td>
308       <table>
309         <tr>
310           <th align=right>| . $locale->text('Customer') . qq|</th>
311           <td colspan=3>$customer</td>
312         </tr>
313         $dunning_level
314         $department
315         <tr>
316           <th align=right nowrap>| . $locale->text('Invoice Number') . qq|</th>
317           <td colspan=3><input name=invnumber size=20></td>
318         </tr>
319         <tr>
320           <th align=right nowrap>| . $locale->text('Order Number') . qq|</th>
321           <td colspan=3><input name=ordnumber size=20></td>
322         </tr>
323         <tr>
324           <th align=right nowrap>| . $locale->text('Notes') . qq|</th>
325           <td colspan=3><input name=notes size=40></td>
326         </tr>
327         <tr>
328           <th align=right nowrap>| . $locale->text('Payment until') . qq|</th>
329           $button1
330         </tr>
331         <input type=hidden name=sort value=transdate>
332       </table>
333     </td>
334   </tr>
335   <tr>
336     <td><hr size=3 noshade></td>
337   </tr>
338   <tr>
339     <td>
340       <table>
341         <tr>
342           <th align=right nowrap>| . $locale->text('Minimum Amount') . qq|</th>
343           <td><input name=minamount size=6></td>
344         </tr>
345         <tr>
346           <th align=right nowrap>| . $locale->text('Group Invoices') . qq|</th>
347           <td><input type=checkbox value=1 name=groupinvoices checked></td>
348         </tr>
349       </table>
350     </td>
351   </tr>
352 </table>
353
354 <input type=hidden name=nextsub value=$form->{nextsub}>
355
356 <input type=hidden name=path value=$form->{path}>
357 <input type=hidden name=login value=$form->{login}>
358 <input type=hidden name=password value=$form->{password}>
359
360 <br>
361 <input class=submit type=submit name=action value="|
362     . $locale->text('Continue') . qq|">
363
364 </form>
365
366 </body>
367
368 $jsscript
369
370 </html>
371 |;
372
373   $lxdebug->leave_sub();
374
375 }
376
377 sub show_invoices {
378   $lxdebug->enter_sub();
379
380   DN->get_invoices(\%myconfig, \%$form);
381   $form->{title} = $locale->text('Start Dunning Process');
382
383   if (@{ $form->{DUNNING_CONFIG} }) {
384     foreach $item (@{ $form->{DUNNING_CONFIG} }) {
385         $form->{selectdunning} .=
386           "<option value=$item->{id}>$item->{dunning_description}</option>";
387     }
388   }
389
390
391   $form->{nextsub} = "save_dunning";
392   
393   $form->{callback} =
394     "$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}&notes=$form->{notes}"
395     unless $form->{callback};
396
397   @column_index = qw(dunning_description active email customername invnumber invdate inv_duedate invamount next_duedate fee interest );
398
399   $column_header{dunning_description} =
400       qq|<th class=listheading>|
401     . $locale->text('Current / Next Level')
402     . qq|</th>|;
403   $column_header{active} =
404       qq|<th class=listheading>|
405     . $locale->text('Active?')
406     . qq|</th>|;
407   $column_header{email} =
408       qq|<th class=listheading>|
409     . $locale->text('eMail?')
410     . qq|</th>|;
411   $column_header{customername} =
412       qq|<th class=listheading>|
413     . $locale->text('Customername')
414     . qq|</th>|;
415   $column_header{invnumber} =
416       qq|<th class=listheading>|
417     . $locale->text('Invno.')
418     . qq|</th>|;
419   $column_header{inv_duedate} =
420       qq|<th class=listheading>|
421     . $locale->text('Inv. Duedate')
422     . qq|</th>|;
423   $column_header{next_duedate} =
424       qq|<th class=listheading>|
425     . $locale->text('Dunning Duedate')
426     . qq|</th>|;
427   $column_header{invdate} =
428       qq|<th class=listheading>|
429     . $locale->text('Invdate')
430     . qq|</th>|;
431   $column_header{invamount} =
432       qq|<th class=listheading>|
433     . $locale->text('Amount')
434     . qq|</th>|;
435   $column_header{fee} =
436       qq|<th class=listheading>|
437     . $locale->text('Total Fees')
438     . qq|</th>|;
439   $column_header{interest} =
440       qq|<th class=listheading>|
441     . $locale->text('Total Interest')
442     . qq|</th>|;
443
444   $form->header;
445
446
447   print qq|
448 <body>
449 <script type="text/javascript" src="js/common.js"></script>
450 <script type="text/javascript" src="js/dunning.js"></script>
451 <form name=Form method=post action=$form->{script}>
452
453
454 <table width=100%>
455   <tr>
456     <th class=listtop colspan=9>$form->{title}</th>
457   </tr>
458   <tr height="5"></tr>
459   <tr>|;
460   map { print "$column_header{$_}\n" } @column_index;
461
462   print qq|
463         </tr>
464 |;
465   my $i = 0;
466   foreach $ref (@{ $form->{DUNNINGS} }) {
467
468     $i++;
469     my $j = $i % 2;
470
471     print qq|
472         <tr valign=top class=listrow$j>
473 |;
474
475   $form->{selectdunning} =~ s/ selected//g;
476   if ($ref->{next_dunning_id} ne "") {
477      $form->{selectdunning} =~ s/value=$ref->{next_dunning_id}/value=$ref->{next_dunning_id} selected/;
478   }
479   
480
481   $dunning = qq|<select name=next_dunning_id_$i>$form->{selectdunning}</select>|;
482
483
484     $column_data{dunning_description}           = qq|<td><input type=hidden name=inv_id_$i size=2 value="$ref->{id}"><input type=hidden name=customer_id_$i size=2 value="$ref->{customer_id}">$ref->{dunning_level}:&nbsp;$dunning</td>|;
485     my $active = "checked";
486     $column_data{active} =
487       qq|<td><input type=checkbox name=active_$i value=1 $active></td>|;
488     my $email = "checked";
489   $column_data{email} =
490     qq|<td><input type=checkbox name=email_$i value=1 $email></td>|;
491     $column_data{next_duedate}           = qq|<td><input type=hidden name=next_duedate_$i size=6 value="$ref->{next_duedate}">$ref->{next_duedate}</td>|;
492
493     $column_data{inv_duedate}           = qq|<td><input type=hidden name=inv_duedate_$i size=6 value="$ref->{duedate}">$ref->{duedate}</td>|;
494     $column_data{invdate}           = qq|<td><input type=hidden name=invdate_$i size=6 value="$ref->{transdate}">$ref->{transdate}</td>|;
495     $column_data{invnumber}           = qq|<td><input type=hidden name=invnumber_$i size=6 value="$ref->{invnumber}">$ref->{invnumber}</td>|;
496     $column_data{customername}           = qq|<td><input type=hidden name=customername_$i size=6 value="$ref->{customername}">$ref->{customername}</td>|;
497     $column_data{invamount}           = qq|<td><input type=hidden name=invamount_$i size=6 value="$ref->{amount}">$ref->{amount}</td>|;
498     $column_data{fee}           = qq|<td><input type=hidden name=fee_$i size=5 value="$ref->{fee}">$ref->{fee}</td>|;
499     $column_data{interest}           = qq|<td><input type=hidden name=interest_$i size=4 value="$ref->{interest}">$ref->{interest}</td>|;
500
501
502
503     map { print "$column_data{$_}\n" } @column_index;
504
505     print qq|
506         </tr>
507 |;
508   }
509
510   $form->{rowcount} = $i;
511
512   print qq|
513       </table>
514     </td>
515   </tr>
516   <tr>
517   <td><hr size=3 noshade></td>
518   </tr>
519 </table>|;
520 &print_options;
521 print qq|
522 <br>
523 <form method=post action=$form->{script}>
524
525 <input name=callback type=hidden value="$form->{callback}">
526 <input name=rowcount type=hidden value="$form->{rowcount}">
527 <input name=nextsub type=hidden value="$form->{nextsub}">
528 <input name=groupinvoices type=hidden value="$form->{groupinvoices}">
529
530
531 <input type=hidden name=path value=$form->{path}>
532 <input type=hidden name=login value=$form->{login}>
533 <input type=hidden name=password value=$form->{password}>
534 <input type="hidden" name="action">
535 <input type="submit" name="dummy" value="|
536     . $locale->text('Continue') . qq|" onclick="this.disabled=true; this.value='Mahnprozess wird gestartet'; document.Form.action.value='weiter'; document.Form.submit()">|;
537   if ($form->{menubar}) {
538     require "$form->{path}/menu.pl";
539     &menubar;
540   }
541
542   print qq|
543
544   </form>
545
546   </body>
547   </html>
548 |;
549
550
551   $lxdebug->leave_sub();
552
553 }
554
555 sub save {
556   $lxdebug->enter_sub();
557
558   for my $i (1 .. $form->{rowcount}) {
559     if ($form->{"dunning_description_$i"} ne "") {
560       $form->isblank("dunning_level_$i", $locale->text('Dunning Level missing in row '). $i);
561       $form->isblank("dunning_description_$i", $locale->text('Dunning Description missing in row '). $i);
562       $form->isblank("terms_$i", $locale->text('Terms missing in row '). $i);
563       $form->isblank("payment_terms_$i", $locale->text('Payment Terms missing in row '). $i);
564     }
565   }
566
567   DN->save_config(\%myconfig, \%$form);
568   $form->redirect($locale->text('Dunning Process Config saved!'));
569
570   $lxdebug->leave_sub();
571 }
572
573 sub save_dunning {
574   $lxdebug->enter_sub();
575
576   my $active=1;
577   my @rows = ();
578   undef($form->{DUNNING_PDFS});
579   if ($form->{groupinvoices}) {
580     while ($active) {
581       $lastcustomer = 0;
582       $form->{inv_ids} = "";
583       $active = 0;
584       @rows = ();
585       for my $i (1 .. $form->{rowcount}) {
586         $form->{"active_$i"} *= 1;
587         $lastcustomer = $form->{"customer_id_$i"} unless ($lastcustomer);
588         if ($form->{"active_$i"} && ($form->{"customer_id_$i"} == $lastcustomer)) {
589           if ($form->{inv_ids}) {
590             $form->{inv_ids} .= qq|,$form->{"inv_id_$i"}|;
591           } else {
592             $form->{inv_ids} = qq|($form->{"inv_id_$i"}|;
593           }
594           $form->{"active_$i"} = 0;
595           $form->{"customer_id_$i"} = 0;
596           push(@rows, $i);
597         } elsif ($form->{"active_$i"}) {
598           $active = 1;
599         } else {
600           $form->{"customer_id_$i"} = 0;
601         }
602       }
603       if ($form->{inv_ids} ne "") {
604         $form->{inv_ids} .= ")";
605         DN->save_dunning(\%myconfig, \%$form, \@rows, $userspath,$spool, $sendmail);
606       }
607     }
608   } else {
609     for my $i (1 .. $form->{rowcount}) {
610       if ($form->{"active_$i"}) {
611         @rows = ();
612         $form->{inv_ids} = qq|($form->{"inv_id_$i"})|;
613         push(@rows, $i);
614         DN->save_dunning(\%myconfig, \%$form, \@rows, $userspath,$spool, $sendmail);
615       }
616     }
617   }
618   if($form->{DUNNING_PDFS}) {
619     DN->melt_pdfs(\%myconfig, \%$form,$spool);
620   }
621
622   $form->redirect($locale->text('Dunning Process started for selected invoices!'));
623
624   $lxdebug->leave_sub();
625 }
626   
627 sub set_email {
628   $lxdebug->enter_sub();
629
630
631   my $callback = "$form->{script}?action=set_email&";
632   map({ $callback .= "$_=" . $form->escape($form->{$_}) . "&" }
633       (qw(login path password name input_subject input_body input_attachment email_subject email_body email_attachment), grep({ /^[fl]_/ } keys %$form)));
634
635   if ($form->{email_attachment}) {
636     $form->{email_attachment} = "checked";
637   }
638   $form->{"title"} = $locale->text("Set eMail text");
639   $form->header();
640   print($form->parse_html_template("dunning/set_email"));
641
642   $lxdebug->leave_sub();
643 }
644
645 sub search {
646   $lxdebug->enter_sub();
647   # setup customer selection
648   $form->all_vc(\%myconfig, "customer", "AR");
649
650   DN->get_config(\%myconfig, \%$form);
651
652   if (@{ $form->{all_customer} }) {
653     map { $customer .= "<option>$_->{name}--$_->{id}\n" }
654       @{ $form->{all_customer} };
655     $customer = qq|<select name=customer><option>\n$customer</select>|;
656   } else {
657     $customer = qq|<input name=customer size=35>|;
658   }
659
660   # dunning levels
661   if (@{ $form->{DUNNING} }) {
662     $form->{selectdunning_level} = "<option></option\n";
663     map {
664       $form->{selectdunning_level} .=
665         "<option value=$_->{id}>$_->{dunning_description}</option>\n"
666     } (@{ $form->{DUNNING} });
667   }
668   $dunning_level = qq| 
669     <tr> 
670     <th align=right nowrap>| . $locale->text('Next Dunning Level') . qq|</th>
671     <td colspan=3><select name=dunning_level>$form->{selectdunning_level}</select></td>
672     </tr>
673     | if $form->{selectdunning_level};
674
675   # departments
676   if (@{ $form->{all_departments} }) {
677     $form->{selectdepartment} = "<option>\n";
678     map {
679       $form->{selectdepartment} .=
680         "<option>$_->{description}--$_->{id}\n"
681     } (@{ $form->{all_departments} });
682   }
683   $department = qq| 
684     <tr> 
685     <th align=right nowrap>| . $locale->text('Department') . qq|</th>
686     <td colspan=3><select name=department>$form->{selectdepartment}</select></td>
687     </tr>
688     | if $form->{selectdepartment};
689   $form->{title}   = $locale->text('Search Dunning');
690   $form->{nextsub} = "show_dunning";
691
692   # use JavaScript Calendar or not
693   $form->{jsscript} = $jscalendar;
694   $jsscript = "";
695   if ($form->{jsscript}) {
696
697     # with JavaScript Calendar
698     $button1 = qq|
699       <td><input name=transdatefrom id=transdatefrom size=11 title="$myconfig{dateformat}">
700       <input type=button name=transdatefrom id="trigger1" value=|
701       . $locale->text('button') . qq|></td>
702       |;
703     $button2 = qq|
704       <td><input name=transdateto id=transdateto size=11 title="$myconfig{dateformat}">
705       <input type=button name=transdateto id="trigger2" value=|
706       . $locale->text('button') . qq|></td>
707       |;
708     $button3 = qq|
709       <td><input name=dunningfrom id=dunningfrom size=11 title="$myconfig{dateformat}">
710       <input type=button name=dunningfrom id="trigger3" value=|
711       . $locale->text('button') . qq|></td>
712       |;
713     $button4 = qq|
714       <td><input name=dunningto id=dunningto size=11 title="$myconfig{dateformat}">
715       <input type=button name=dunningto id="trigger4" value=|
716       . $locale->text('button') . qq|></td>
717       |;
718
719     #write Trigger
720     $jsscript =
721       Form->write_trigger(\%myconfig, "4", "transdatefrom", "BR", "trigger1", "transdateto", "BR", "trigger2", "dunningfrom", "BR", "trigger3", "dunningto", "BR", "trigger4");
722   } else {
723
724     # without JavaScript Calendar
725     $button1 =
726       qq|<td><input name=transdatefrom id=transdatefrom size=11 title="$myconfig{dateformat}"></td>|;
727     $button2 =
728       qq|<td><input name=transdateto id=transdateto size=11 title="$myconfig{dateformat}"></td>|;
729     $button1 =
730       qq|<td><input name=dunningfrom id=dunningfrom size=11 title="$myconfig{dateformat}"></td>|;
731     $button1 =
732       qq|<td><input name=dunningfrom id=dunningto size=11 title="$myconfig{dateformat}"></td>|;
733   }
734
735   $form->{fokus} = "search.customer";
736   $form->header;
737   print qq|
738 <body onLoad="fokus()">
739
740 <form method=post name="search" action=$form->{script}>
741
742 <table width=100%>
743   <tr><th class=listtop>$form->{title}</th></tr>
744   <tr height="5"></tr>
745   <tr>
746     <td>
747       <table>
748         <tr>
749           <th align=right>| . $locale->text('Customer') . qq|</th>
750           <td colspan=3>$customer</td>
751         </tr>
752         $dunning_level
753         $department
754         <tr>
755           <th align=right nowrap>| . $locale->text('Invoice Number') . qq|</th>
756           <td colspan=3><input name=invnumber size=20></td>
757         </tr>
758         <tr>
759           <th align=right nowrap>| . $locale->text('Order Number') . qq|</th>
760           <td colspan=3><input name=ordnumber size=20></td>
761         </tr>
762         <tr>
763           <th align=right nowrap>| . $locale->text('Notes') . qq|</th>
764           <td colspan=3><input name=notes size=40></td>
765         </tr>
766         <tr>
767           <th align=right nowrap>| . $locale->text('Invdate from') . qq|</th>
768           $button1
769           <th align=right nowrap>| . $locale->text('To') . qq|</th>
770           $button2
771         </tr>
772         <tr>
773           <th align=right nowrap>| . $locale->text('Dunning Date from') . qq|</th>
774           $button3
775           <th align=right nowrap>| . $locale->text('To') . qq|</th>
776           $button4
777         </tr>
778
779         <input type=hidden name=sort value=transdate>
780       </table>
781     </td>
782   </tr>
783   <tr>
784     <td><hr size=3 noshade></td>
785   </tr>
786   <tr>
787     <td>
788       <table>
789         <tr>
790           <th align=right nowrap>| . $locale->text('Show old dunnings') . qq|</th>
791           <td><input type=checkbox value=1 name=showold></td>
792         </tr>
793       </table>
794     </td>
795   </tr>
796 </table>
797
798 <input type=hidden name=nextsub value=$form->{nextsub}>
799
800 <input type=hidden name=path value=$form->{path}>
801 <input type=hidden name=login value=$form->{login}>
802 <input type=hidden name=password value=$form->{password}>
803
804 <br>
805 <input class=submit type=submit name=action value="|
806     . $locale->text('Continue') . qq|">
807
808 </form>
809
810 </body>
811
812 $jsscript
813
814 </html>
815 |;
816
817   $lxdebug->leave_sub();
818
819 }
820
821 sub show_dunning {
822   $lxdebug->enter_sub();
823
824   DN->get_dunning(\%myconfig, \%$form);
825   $form->{title} = $locale->text('Dunning overview');
826
827
828
829
830   
831   $form->{callback} =
832     "$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}&notes=$form->{notes}&showold=$form->{showold}&dunning_level=$form->{dunning_level}"
833     unless $form->{callback};
834
835   @column_index = qw(dunning_description customername invnumber invdate inv_duedate invamount dunning_date next_duedate fee interest );
836
837   $column_header{dunning_description} =
838       qq|<th class=listheading>|
839     . $locale->text('Dunning Level')
840     . qq|</th>|;
841   $column_header{customername} =
842       qq|<th class=listheading>|
843     . $locale->text('Customername')
844     . qq|</th>|;
845   $column_header{invnumber} =
846       qq|<th class=listheading>|
847     . $locale->text('Invnumber')
848     . qq|</th>|;
849   $column_header{inv_duedate} =
850       qq|<th class=listheading>|
851     . $locale->text('Invoice Duedate')
852     . qq|</th>|;
853   $column_header{dunning_date} =
854       qq|<th class=listheading>|
855     . $locale->text('Dunning Date')
856     . qq|</th>|;
857   $column_header{next_duedate} =
858       qq|<th class=listheading>|
859     . $locale->text('Dunning Duedate')
860     . qq|</th>|;
861   $column_header{invdate} =
862       qq|<th class=listheading>|
863     . $locale->text('Invdate')
864     . qq|</th>|;
865   $column_header{invamount} =
866       qq|<th class=listheading>|
867     . $locale->text('Amount')
868     . qq|</th>|;
869   $column_header{fee} =
870       qq|<th class=listheading>|
871     . $locale->text('Total Fees')
872     . qq|</th>|;
873   $column_header{interest} =
874       qq|<th class=listheading>|
875     . $locale->text('Total Interest')
876     . qq|</th>|;
877
878   $form->header;
879
880
881   print qq|
882 <body>
883 <script type="text/javascript" src="js/common.js"></script>
884 <script type="text/javascript" src="js/dunning.js"></script>
885 <form method=post action=$form->{script}>
886
887
888 <table width=100%>
889   <tr>
890     <th class=listtop colspan=9>$form->{title}</th>
891   </tr>
892   <tr height="5"></tr>
893   <tr>|;
894   map { print "$column_header{$_}\n" } @column_index;
895
896   print qq|
897         </tr>
898 |;
899   my $i = 0;
900   foreach $ref (@{ $form->{DUNNINGS} }) {
901
902     $i++;
903     my $j = $i % 2;
904
905     print qq|
906         <tr valign=top class=listrow$j>
907 |;
908
909   
910
911   $dunning = qq|<select name=next_dunning_id_$i>$form->{selectdunning}</select>|;
912
913
914     $column_data{dunning_description}           = qq|<td>$ref->{dunning_description}</td>|;
915     my $active = "checked";
916     $column_data{dunning_date}           = qq|<td>$ref->{dunning_date}</td>|;
917     $column_data{next_duedate}           = qq|<td>$ref->{dunning_duedate}</td>|;
918
919     $column_data{inv_duedate}           = qq|<td>$ref->{duedate}</td>|;
920     $column_data{invdate}           = qq|<td>$ref->{transdate}</td>|;
921     $column_data{invnumber}           = qq|<td><a href=ar.pl?action=edit&id=$ref->{id}&path=$form->{path}&login=$form->{login}&password=$form->{password}&callback=$form->{callback}>$ref->{invnumber}</a></td>|;
922     $column_data{customername}           = qq|<td>$ref->{customername}</td>|;
923     $column_data{invamount}           = qq|<td>$ref->{amount}</td>|;
924     $column_data{fee}           = qq|<td>$ref->{fee}</td>|;
925     $column_data{interest}           = qq|<td>$ref->{interest}</td>|;
926
927
928
929     map { print "$column_data{$_}\n" } @column_index;
930
931     print qq|
932         </tr>
933 |;
934   }
935
936   $form->{rowcount} = $i;
937
938   print qq|
939       </table>
940     </td>
941   </tr>
942   <tr>
943   <td><hr size=3 noshade></td>
944   </tr>
945 </table>
946
947 <br>
948 <form method=post action=$form->{script}>
949
950 <input name=callback type=hidden value="$form->{callback}">
951 <input name=rowcount type=hidden value="$form->{rowcount}">
952 <input name=nextsub type=hidden value="$form->{nextsub}">
953
954
955 <input type=hidden name=path value=$form->{path}>
956 <input type=hidden name=login value=$form->{login}>
957 <input type=hidden name=password value=$form->{password}>
958 |;
959
960   if ($form->{menubar}) {
961     require "$form->{path}/menu.pl";
962     &menubar;
963   }
964
965   print qq|
966
967   </form>
968
969   </body>
970   </html>
971 |;
972
973
974   $lxdebug->leave_sub();
975
976 }
977 # end of main
978