Vermeidung von SQL injection durch Verwendung von parametrisierten Queries. Zusätzlic...
[kivitendo-erp.git] / bin / mozilla / dn.pl
index 50c602b..bd96d3e 100644 (file)
@@ -105,7 +105,7 @@ sub edit_config {
 
 <table width=100%>
   <tr>
-    <th class=listtop colspan=9>$form->{title}</th>
+    <th class=listtop colspan=10>$form->{title}</th>
   </tr>
   <tr height="5"></tr>
   <tr>|;
@@ -207,14 +207,7 @@ sub edit_config {
 <input type=hidden name=password value=$form->{password}>
 
 <input class=submit type=submit name=action value="|
-    . $locale->text('Save') . qq|">|;
-
-  if ($form->{menubar}) {
-    require "$form->{path}/menu.pl";
-    &menubar;
-  }
-
-  print qq|
+    . $locale->text('Save') . qq|">
 
   </form>
 
@@ -328,7 +321,6 @@ sub add {
           <th align=right nowrap>| . $locale->text('Payment until') . qq|</th>
           $button1
         </tr>
-        <input type=hidden name=sort value=transdate>
       </table>
     </td>
   </tr>
@@ -453,7 +445,7 @@ sub show_invoices {
 
 <table width=100%>
   <tr>
-    <th class=listtop colspan=9>$form->{title}</th>
+    <th class=listtop colspan=11>$form->{title}</th>
   </tr>
   <tr height="5"></tr>
   <tr>|;
@@ -482,10 +474,10 @@ sub show_invoices {
 
 
     $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>|;
-    my $active = "checked";
+    my $active = ($ref->{active}) ? "checked" : "";
     $column_data{active} =
       qq|<td><input type=checkbox name=active_$i value=1 $active></td>|;
-    my $email = "checked";
+    my $email = ($ref->{email}) ? "checked" : "";
   $column_data{email} =
     qq|<td><input type=checkbox name=email_$i value=1 $email></td>|;
     $column_data{next_duedate}           = qq|<td><input type=hidden name=next_duedate_$i size=6 value="$ref->{next_duedate}">$ref->{next_duedate}</td>|;
@@ -517,8 +509,8 @@ sub show_invoices {
   <td><hr size=3 noshade></td>
   </tr>
 </table>|;
-&print_options;
-print qq|
+  &print_options;
+  print qq|
 <br>
 <form method=post action=$form->{script}>
 
@@ -530,20 +522,10 @@ print qq|
 
 <input type=hidden name=path value=$form->{path}>
 <input type=hidden name=login value=$form->{login}>
-<input type=hidden name=password value=$form->{password}>|;
-#print qq|
-# <input type="submit" name="action" value="|
-#     . $locale->text('Continue') . qq|">|;
-print qq|
+<input type=hidden name=password value=$form->{password}>
 <input type="hidden" name="action">
 <input type="submit" name="dummy" value="|
-    . $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()">|;
-  if ($form->{menubar}) {
-    require "$form->{path}/menu.pl";
-    &menubar;
-  }
-
-  print qq|
+    . $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()">
 
   </form>
 
@@ -569,6 +551,12 @@ sub save {
   }
 
   DN->save_config(\%myconfig, \%$form);
+  # saving the history
+  if(!exists $form->{addition} && $form->{id} ne "") {
+       $form->{addition} = "SAVED FOR DUNNING";
+       $form->save_history($form->dbconnect(\%myconfig));
+  }
+  # /saving the history 
   $form->redirect($locale->text('Dunning Process Config saved!'));
 
   $lxdebug->leave_sub();
@@ -583,18 +571,14 @@ sub save_dunning {
   if ($form->{groupinvoices}) {
     while ($active) {
       $lastcustomer = 0;
-      $form->{inv_ids} = "";
+      $form->{inv_ids} = [];
       $active = 0;
       @rows = ();
       for my $i (1 .. $form->{rowcount}) {
         $form->{"active_$i"} *= 1;
         $lastcustomer = $form->{"customer_id_$i"} unless ($lastcustomer);
         if ($form->{"active_$i"} && ($form->{"customer_id_$i"} == $lastcustomer)) {
-          if ($form->{inv_ids}) {
-            $form->{inv_ids} .= qq|,$form->{"inv_id_$i"}|;
-          } else {
-            $form->{inv_ids} = qq|($form->{"inv_id_$i"}|;
-          }
+          push(@{ $form->{inv_ids} }, $form->{"inv_id_$i"});
           $form->{"active_$i"} = 0;
           $form->{"customer_id_$i"} = 0;
           push(@rows, $i);
@@ -604,8 +588,7 @@ sub save_dunning {
           $form->{"customer_id_$i"} = 0;
         }
       }
-      if ($form->{inv_ids} ne "") {
-        $form->{inv_ids} .= ")";
+      if (scalar(@{ $form->{inv_ids} }) != 0) {
         DN->save_dunning(\%myconfig, \%$form, \@rows, $userspath,$spool, $sendmail);
       }
     }
@@ -613,7 +596,7 @@ sub save_dunning {
     for my $i (1 .. $form->{rowcount}) {
       if ($form->{"active_$i"}) {
         @rows = ();
-        $form->{inv_ids} = qq|($form->{"inv_id_$i"})|;
+        $form->{inv_ids} = [ $form->{"inv_id_$i"} ];
         push(@rows, $i);
         DN->save_dunning(\%myconfig, \%$form, \@rows, $userspath,$spool, $sendmail);
       }
@@ -622,7 +605,12 @@ sub save_dunning {
   if($form->{DUNNING_PDFS}) {
     DN->melt_pdfs(\%myconfig, \%$form,$spool);
   }
-
+  # saving the history
+  if(!exists $form->{addition} && $form->{id} ne "") {
+       $form->{addition} = "DUNNING STARTED";
+       $form->save_history($form->dbconnect(\%myconfig));
+  }
+  # /saving the history 
   $form->redirect($locale->text('Dunning Process started for selected invoices!'));
 
   $lxdebug->leave_sub();
@@ -780,7 +768,6 @@ sub search {
           $button4
         </tr>
 
-        <input type=hidden name=sort value=transdate>
       </table>
     </td>
   </tr>
@@ -891,7 +878,7 @@ sub show_dunning {
 
 <table width=100%>
   <tr>
-    <th class=listtop colspan=9>$form->{title}</th>
+    <th class=listtop colspan=10>$form->{title}</th>
   </tr>
   <tr height="5"></tr>
   <tr>|;
@@ -901,10 +888,13 @@ sub show_dunning {
         </tr>
 |;
   my $i = 0;
+  my $j = 0;
+  my $previous_customer_id;
   foreach $ref (@{ $form->{DUNNINGS} }) {
-
     $i++;
-    my $j = $i % 2;
+    $j++ if ($previous_customer_id != $ref->{customer_id});
+    $j = $j % 2;
+    $previous_customer_id = $ref->{customer_id};
 
     print qq|
         <tr valign=top class=listrow$j>
@@ -913,16 +903,20 @@ sub show_dunning {
   
 
   $dunning = qq|<select name=next_dunning_id_$i>$form->{selectdunning}</select>|;
-
-
-    $column_data{dunning_description}           = qq|<td>$ref->{dunning_description}</td>|;
+    my $script = "";
+    if ($ref->{invoice}) {
+      $script = "is.pl";
+    } else {
+      $script = "ar.pl";
+    }
+    $column_data{dunning_description}           = qq|<td><a href=dn.pl?action=print_dunning&dunning_id=$ref->{dunning_id}&customer_id=$ref->{customer_id}&format=pdf&media=screen&path=$form->{path}&login=$form->{login}&password=$form->{password}&callback=$form->{callback}>$ref->{dunning_description}</a></td>|;
     my $active = "checked";
     $column_data{dunning_date}           = qq|<td>$ref->{dunning_date}</td>|;
     $column_data{next_duedate}           = qq|<td>$ref->{dunning_duedate}</td>|;
 
     $column_data{inv_duedate}           = qq|<td>$ref->{duedate}</td>|;
     $column_data{invdate}           = qq|<td>$ref->{transdate}</td>|;
-    $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>|;
+    $column_data{invnumber}           = qq|<td><a href=$script?action=edit&id=$ref->{id}&path=$form->{path}&login=$form->{login}&password=$form->{password}&callback=$form->{callback}>$ref->{invnumber}</a></td>|;
     $column_data{customername}           = qq|<td>$ref->{customername}</td>|;
     $column_data{invamount}           = qq|<td>$ref->{amount}</td>|;
     $column_data{fee}           = qq|<td>$ref->{fee}</td>|;
@@ -959,14 +953,6 @@ sub show_dunning {
 <input type=hidden name=path value=$form->{path}>
 <input type=hidden name=login value=$form->{login}>
 <input type=hidden name=password value=$form->{password}>
-|;
-
-  if ($form->{menubar}) {
-    require "$form->{path}/menu.pl";
-    &menubar;
-  }
-
-  print qq|
 
   </form>
 
@@ -978,5 +964,21 @@ sub show_dunning {
   $lxdebug->leave_sub();
 
 }
+
+sub print_dunning {
+  $lxdebug->enter_sub();
+
+  DN->print_dunning(\%myconfig, \%$form, $form->{dunning_id}, $form->{customer_id}, $userspath, $spool, $sendmail);
+
+  if($form->{DUNNING_PDFS}) {
+    DN->melt_pdfs(\%myconfig, \%$form,$spool);
+  } else {
+    $form->redirect($locale->text('Could not create dunning copy!'));
+  }
+
+  $lxdebug->leave_sub();
+
+}
+
 # end of main