Beim Anlegen von Buchungsgruppen die in den Benutzereinstellungen ausgewählten Standa...
[kivitendo-erp.git] / bin / mozilla / is.pl
index 163ac14..9810748 100644 (file)
@@ -69,8 +69,6 @@ sub add {
   }
   &invoice_links;
   &prepare_invoice;
-  $form->{format} = "pdf";
-
   &display_form;
 
   $lxdebug->leave_sub();
@@ -138,6 +136,11 @@ sub invoice_links {
 
   $cp_id = $form->{cp_id};
   IS->get_customer(\%myconfig, \%$form);
+
+  #quote all_customer Bug 133
+  foreach $ref (@{ $form->{all_customer} }) {
+    $ref->{name} = $form->quote($ref->{name});
+  }
   if ($id) {
     $form->{id} = $id;
   }
@@ -158,7 +161,7 @@ sub invoice_links {
   }
 
   # currencies
-  @curr = split /:/, $form->{currencies};
+  @curr = split(/:/, $form->{currencies});
   chomp $curr[0];
   $form->{defaultcurrency} = $curr[0];
 
@@ -166,7 +169,7 @@ sub invoice_links {
 
   $form->{oldcustomer} = "$form->{customer}--$form->{customer_id}";
 
-  if ($form->{all_customer}) {
+  if (@{ $form->{all_customer} }) {
     $form->{customer} = "$form->{customer}--$form->{customer_id}";
     map { $form->{selectcustomer} .= "<option>$_->{name}--$_->{id}\n" }
       (@{ $form->{all_customer} });
@@ -256,10 +259,11 @@ sub prepare_invoice {
     #     # get pricegroups for parts
     #     IS->get_pricegroups_for_parts(\%myconfig, \%$form);
 
+    my $i = 0;
+
     foreach $ref (@{ $form->{invoice_details} }) {
       $i++;
 
       map { $form->{"${_}_$i"} = $ref->{$_} } keys %{$ref};
       $form->{"discount_$i"} =
         $form->format_amount(\%myconfig, $form->{"discount_$i"} * 100);
@@ -306,6 +310,9 @@ sub form_header {
     }
   }
 
+  $form->{radier} =
+    ($form->current_date(\%myconfig) eq $form->{gldate}) ? 1 : 0;
+
   $payment = qq|<option value=""></option>|;
   foreach $item (@{ $form->{payment_terms} }) {
     if ($form->{payment_id} eq $item->{id}) {
@@ -315,16 +322,22 @@ sub form_header {
     }
   }
 
+  my $set_duedate_url =
+    "$form->{script}?login=$form->{login}&path=$form->{path}&password=$form->{password}&action=set_duedate";
+
+  my $pjx = new CGI::Ajax( 'set_duedate' => $set_duedate_url );
+  push(@ { $form->{AJAX} }, $pjx);
 
   if (@{ $form->{TAXZONE} }) {
     $form->{selecttaxzone} = "";
     foreach $item (@{ $form->{TAXZONE} }) {
       if ($item->{id} == $form->{taxzone_id}) {
         $form->{selecttaxzone} .=
-          "<option value=$item->{id} selected>$item->{description}</option>";
+          "<option value=$item->{id} selected>" . H($item->{description}) .
+          "</option>";
       } else {
         $form->{selecttaxzone} .=
-          "<option value=$item->{id}>$item->{description}</option>";
+          "<option value=$item->{id}>" . H($item->{description}) . "</option>";
       }
 
     }
@@ -334,11 +347,6 @@ sub form_header {
       $form->{selecttaxzone} =~ s/value=$form->{taxzone_id}/value=$form->{taxzone_id} selected/;
     }
   }
-  if ($form->{rowcount} >0) {
-    $form->{selecttaxzone} =~ /<option value=\d+ selected>.*?<\/option>/;
-    $form->{selecttaxzone} = $&;
-  }
-  
 
   $taxzone = qq|
              <tr>
@@ -351,12 +359,12 @@ sub form_header {
   if (@{ $form->{SHIPTO} }) {
     $form->{selectshipto} = "<option value=0></option>";
     foreach $item (@{ $form->{SHIPTO} }) {
-      if ($item->{id} == $form->{shipto_id}) {
+      if ($item->{shipto_id} == $form->{shipto_id}) {
         $form->{selectshipto} .=
-          "<option value=$item->{id} selected>$item->{shiptoname}</option>";
+          "<option value=$item->{shipto_id} selected>$item->{shiptoname} $item->{shiptodepartment_1}</option>";
       } else {
         $form->{selectshipto} .=
-          "<option value=$item->{id}>$item->{shiptoname}</option>";
+          "<option value=$item->{shipto_id}>$item->{shiptoname} $item->{shiptodepartment}</option>";
       }
 
     }
@@ -369,7 +377,7 @@ sub form_header {
 
   $shipto = qq|
                <th align=right>| . $locale->text('Shipping Address') . qq|</th>
-               <td><select name=shipto_id>$form->{selectshipto}</select></td>
+               <td><select name=shipto_id style="width:200px;">$form->{selectshipto}</select></td>
                <input type=hidden name=selectshipto value="$form->{selectshipto}">|;
 
 
@@ -381,6 +389,9 @@ sub form_header {
       s/option>\Q$form->{$item}\E/option selected>$form->{$item}/;
   }
 
+  #quote customer Bug 133
+  $form->{selectcustomer} = $form->quote($form->{selectcustomer});
+  
   #build contacts
   if ($form->{all_contacts}) {
 
@@ -652,7 +663,7 @@ sub form_header {
               $dunning
              <tr>
                <th align=right nowrap>| . $locale->text('Record in') . qq|</th>
-               <td colspan=3><select name=AR>$form->{selectAR}</select></td>
+               <td colspan=3><select name=AR style="width:280px;">$form->{selectAR}</select></td>
                <input type=hidden name=selectAR value="$form->{selectAR}">
              </tr>
               $taxzone
@@ -899,7 +910,7 @@ sub form_footer {
              <tr valign=top>
                <td>$notes</td>
                <td>$intnotes</td>
-                <td><select name=payment_id tabindex=24>$payment
+                <td><select name=payment_id onChange="set_duedate(['payment_id__' + this.value],['duedate'])">$payment
                 </select></td>
              </tr>
            </table>
@@ -1002,8 +1013,10 @@ if ($form->{type} eq "credit_note") {
 
     # format amounts
     $totalpaid += $form->{"paid_$i"};
-    $form->{"paid_$i"} =
-      $form->format_amount(\%myconfig, $form->{"paid_$i"}, 2);
+    if ($form->{"paid_$i"}) {
+      $form->{"paid_$i"} =
+        $form->format_amount(\%myconfig, $form->{"paid_$i"}, 2);
+    }
     $form->{"exchangerate_$i"} =
       $form->format_amount(\%myconfig, $form->{"exchangerate_$i"});
 
@@ -1079,6 +1092,9 @@ if ($form->{type} eq "credit_note") {
       . $locale->text('Storno') . qq|">| unless ($form->{storno});
     print qq|<input class=submit type=submit name=action value="|
       . $locale->text('Post Payment') . qq|">
+|;
+    print qq|<input class=submit type=submit name=action value="|
+      . $locale->text('Use As Template') . qq|">
 |;
   if ($form->{id} && !($form->{type} eq "credit_note")) {
     print qq|
@@ -1086,6 +1102,12 @@ if ($form->{type} eq "credit_note") {
       . $locale->text('Credit Note') . qq|">
 |;
   }
+    if ($form->{radier}) {
+    print qq|
+    <input class=submit type=submit name=action value="|
+      . $locale->text('Delete') . qq|">
+|;
+  }
 
 
     if ($invdate > $closedto) {
@@ -1190,8 +1212,6 @@ sub update {
 
   } else {
 
-    $form->{"selected_unit_$i"} = $form->{"unit_$i"};
-
     IS->retrieve_item(\%myconfig, \%$form);
 
     $rows = scalar @{ $form->{item_list} };
@@ -1209,7 +1229,7 @@ sub update {
 
       } else {
 
-        $sellprice = $form->format_amount(\%myconfig, $form->{"sellprice_$i"});
+        $sellprice = $form->parse_amount(\%myconfig, $form->{"sellprice_$i"});
 
         map { $form->{item_list}[$i]{$_} =~ s/\"/&quot;/g }
           qw(partnumber description unit);
@@ -1326,6 +1346,7 @@ sub post_payment {
 
   ($form->{AR})      = split /--/, $form->{AR};
   ($form->{AR_paid}) = split /--/, $form->{AR_paid};
+  relink_accounts();
   $form->redirect($locale->text(' Payment posted!'))
       if (IS->post_payment(\%myconfig, \%$form));
     $form->error($locale->text('Cannot post payment!'));
@@ -1392,6 +1413,7 @@ sub post {
       $form->{invnumber} = $form->update_defaults(\%myconfig, "invnumber");
     }
   }
+  relink_accounts();
   if ($print_post) {
     if (!(IS->post_invoice(\%myconfig, \%$form))) {
       $form->error($locale->text('Cannot post invoice!'));
@@ -1419,6 +1441,18 @@ sub print_and_post {
 
 }
 
+sub use_as_template {
+  $lxdebug->enter_sub();
+
+  map { delete $form->{$_} } qw(printed emailed queued invnumber invdate deliverydate id datepaid_1 source_1 memo_1 paid_1 exchangerate_1 AP_paid_1 storno);
+  $form->{paidaccounts} = 1;
+  $form->{rowcount}--;
+  $form->{invdate} = $form->current_date(\%myconfig);
+  &display_form;
+
+  $lxdebug->leave_sub();
+}
+
 sub storno {
   $lxdebug->enter_sub();
 
@@ -1430,7 +1464,6 @@ sub storno {
   $form->{storno} = 1;
   $form->{id} = "";
   $form->{invnumber} = "Storno zu " . $form->{invnumber};
-  $form->{rowcount}--;
 
   &post();
   $lxdebug->leave_sub();