X-Git-Url: http://wagnertech.de/gitweb/gitweb.cgi/mfinanz.git/blobdiff_plain/cfc6a60d53597f6a879b28af37f84b4b5fa4cc6b..b6dc5623d93c1be1c54248d4512e80f495af2899:/bin/mozilla/is.pl
diff --git a/bin/mozilla/is.pl b/bin/mozilla/is.pl
index f4556cf2c..65cc0609d 100644
--- a/bin/mozilla/is.pl
+++ b/bin/mozilla/is.pl
@@ -34,9 +34,12 @@
 use SL::IS;
 use SL::PE;
 use Data::Dumper;
+use List::Util qw(max);
 
-require "$form->{path}/io.pl";
-require "$form->{path}/arap.pl";
+require "bin/mozilla/io.pl";
+require "bin/mozilla/invoice_io.pl";
+require "bin/mozilla/arap.pl";
+require "bin/mozilla/drafts.pl";
 
 1;
 
@@ -44,7 +47,9 @@ require "$form->{path}/arap.pl";
 
 sub add {
   $lxdebug->enter_sub();
-  
+
+  return $lxdebug->leave_sub() if (load_draft_maybe());
+
   if ($form->{type} eq "credit_note") {
     $form->{title} = $locale->text('Add Credit Note');
 
@@ -58,7 +63,7 @@ sub add {
 
 
   $form->{callback} =
-    "$form->{script}?action=add&type=$form->{type}&login=$form->{login}&path=$form->{path}&password=$form->{password}"
+    "$form->{script}?action=add&type=$form->{type}&login=$form->{login}&password=$form->{password}"
     unless $form->{callback};
 
   $form{jsscript} = "date";
@@ -77,6 +82,9 @@ sub add {
 sub edit {
   $lxdebug->enter_sub();
 
+  # show history button
+  $form->{javascript} = qq||;
+  #/show hhistory button
 
   if ($myconfig{acs} =~ "AR--Add Sales Invoice" || $myconfig{acs} =~ "AR--AR")
   {
@@ -115,6 +123,7 @@ sub invoice_links {
   if ($form->{all_customer}) {
     unless ($form->{customer_id}) {
       $form->{customer_id} = $form->{all_customer}->[0]->{id};
+      $form->{salesman_id} = $form->{all_customer}->[0]->{salesman_id};
     }
   }
 
@@ -160,21 +169,8 @@ sub invoice_links {
     $form->{shipto_id} = $shipto_id;
   }
 
-  # currencies
-  @curr = split(/:/, $form->{currencies});
-  chomp $curr[0];
-  $form->{defaultcurrency} = $curr[0];
-
-  map { $form->{selectcurrency} .= "\n"
     } (@{ $form->{all_departments} });
   }
 
   $form->{employee} = "$form->{employee}--$form->{employee_id}";
 
-  # sales staff
-  if ($form->{all_employees}) {
-    $form->{selectemployee} = "";
-    map { $form->{selectemployee} .= "\n";
     }
 
     if ($key eq "AR_paid") {
@@ -291,25 +281,20 @@ sub prepare_invoice {
 sub form_header {
   $lxdebug->enter_sub();
 
-  if ($edit) {
+  $form->{employee_id} = $form->{old_employee_id} if $form->{old_employee_id};
+  $form->{salesman_id} = $form->{old_salesman_id} if $form->{old_salesman_id};
 
+  if ($edit) {
     if ($form->{type} eq "credit_note") {
       $form->{title} = $locale->text('Edit Credit Note');
-    
-      if ($form->{storno}) {
-        $form->{title} = $locale->text('Edit Storno Credit Note');
-      }
+      $form->{title} = $locale->text('Edit Storno Credit Note') if $form->{storno};
     } else {
       $form->{title} = $locale->text('Edit Sales Invoice');
-    
-      if ($form->{storno}) {
-        $form->{title} = $locale->text('Edit Storno Invoice');
-      }
+      $form->{title} = $locale->text('Edit Storno Invoice')     if $form->{storno};
     }
   }
-
-  $form->{radier} =
-    ($form->current_date(\%myconfig) eq $form->{gldate}) ? 1 : 0;
+  $form->{defaultcurrency} = $form->get_default_currency(\%myconfig);
+  $form->{radier}          = ($form->current_date(\%myconfig) eq $form->{gldate}) ? 1 : 0;
 
   $payment = qq||;
   foreach $item (@{ $form->{payment_terms} }) {
@@ -320,73 +305,113 @@ sub form_header {
     }
   }
 
-  my $set_duedate_url =
-    "$form->{script}?login=$form->{login}&path=$form->{path}&password=$form->{password}&action=set_duedate";
+  my $set_duedate_url = "$form->{script}?login=$form->{login}&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} .=
-          "";
-      } else {
-        $form->{selecttaxzone} .=
-          "";
-      }
-
-    }
-  } else {
-    $form->{selecttaxzone} =~ s/ selected//g;
-    if ($form->{taxzone_id} ne "") {
-      $form->{selecttaxzone} =~ s/value=$form->{taxzone_id}/value=$form->{taxzone_id} selected/;
-    }
+  my @old_project_ids = ($form->{"globalproject_id"});
+  map { push @old_project_ids, $form->{"project_id_$_"} if $form->{"project_id_$_"}; } 1..$form->{"rowcount"};
+
+  $form->get_lists("contacts"      => "ALL_CONTACTS",
+                   "shipto"        => "ALL_SHIPTO",
+                   "projects"      => { "key"    => "ALL_PROJECTS",
+                                        "all"    => 0,
+                                        "old_id" => \@old_project_ids },
+                   "employees"     => "ALL_SALESMEN",
+                   "taxzones"      => "ALL_TAXZONES",
+                   "currencies"    => "ALL_CURRENCIES",
+                   "customers"     => "ALL_CUSTOMERS",
+                   "price_factors" => "ALL_PRICE_FACTORS");
+
+  my %labels;
+  my @values = (undef);
+  foreach my $item (@{ $form->{"ALL_CONTACTS"} }) {
+    push(@values, $item->{"cp_id"});
+    $labels{$item->{"cp_id"}} = $item->{"cp_name"} .  ($item->{"cp_abteilung"} ? " ($item->{cp_abteilung})" : "");
+  }
+  my $contact;
+  if (scalar @values > 1) {
+    $contact = qq|
+    
+      | | . $locale->text('Contact Person') . qq| | 
+      | .  NTI($cgi->popup_menu('-name' => 'cp_id', '-values' => \@values, '-style' => 'width: 250px',
+                                    '-labels' => \%labels, '-default' => $form->{"cp_id"})) . qq|
+       | 
+    
|;
   }
 
-  $taxzone = qq|
-	      
-		| | . $locale->text('Steuersatz') . qq| | 
-		 | 
-		
-	      
|;
+  %labels = ();
+  @values = ();
+  foreach my $item (@{ $form->{"ALL_SALESMEN"} }) {
+    push(@values, $item->{"id"});
+    $labels{$item->{id}} = $item->{name} ne "" ? $item->{name} : $item->{login};
+  }
 
-  my @old_project_ids = ($form->{"globalproject_id"});
-  map({ push(@old_project_ids, $form->{"project_id_$_"})
-          if ($form->{"project_id_$_"}); } (1..$form->{"rowcount"}));
+  my $employees = qq|
+    
+      | | . $locale->text('Employee') . qq| | 
+      | . NTI($cgi->popup_menu('-name' => 'employee_id', '-default' => $form->{"employee_id"},
+                                   '-values' => \@values, '-labels' => \%labels)) . qq|
+       | 
+    
|;
 
-  $form->get_lists("contacts" => "ALL_CONTACTS",
-                   "shipto" => "ALL_SHIPTO",
-                   "projects" => { "key" => "ALL_PROJECTS",
-                                   "all" => 0,
-                                   "old_id" => \@old_project_ids });
 
-  my (%labels, @values);
-  foreach my $item (@{ $form->{"ALL_CONTACTS"} }) {
-    push(@values, $item->{"cp_id"});
-    $labels{$item->{"cp_id"}} = $item->{"cp_name"} .
-      ($item->{"cp_abteilung"} ? " ($item->{cp_abteilung})" : "");
+  %labels = ();
+  @values = ();
+  foreach my $item (@{ $form->{"ALL_CUSTOMERS"} }) {
+    push(@values, $item->{name}.qq|--|.$item->{"id"});
+    $labels{$item->{name}.qq|--|.$item->{"id"}} = $item->{"name"};
   }
-  my $contact =
-    NTI($cgi->popup_menu('-name' => 'cp_id', '-values' => \@values,
-                         '-labels' => \%labels, '-default' => $form->{"cp_id"}));
+
+  $form->{selectcustomer} = ($myconfig{vclimit} > scalar(@values));
+
+  my $customers = qq|
+      | . $locale->text('Customer') . qq| | 
+      | .
+        (($myconfig{vclimit} <=  scalar(@values))
+              ? qq||
+              : (NTI($cgi->popup_menu('-name' => 'customer', '-default' => $form->{oldcustomer},
+                             '-onChange' => 'document.getElementById(\'update_button\').click();',
+                             '-values' => \@values, '-labels' => \%labels, '-style' => 'width: 250px')))) . qq|
+        
+       | |;
 
   %labels = ();
   @values = ("");
   foreach my $item (@{ $form->{"ALL_SHIPTO"} }) {
     push(@values, $item->{"shipto_id"});
-    $labels{$item->{"shipto_id"}} =
-      $item->{"shiptoname"} . " " . $item->{"shiptodepartment_1"};
+    $labels{$item->{"shipto_id"}} = join "; ", grep { $_ } map { $item->{"shipto${_}" } } qw(name department_1 street city);
   }
 
-  my $shipto = qq|
-		| . $locale->text('Shipping Address') . qq| | 
-		| .
-    NTI($cgi->popup_menu('-name' => 'shipto_id', '-values' => \@values,
-                         '-labels' => \%labels, '-default' => $form->{"shipto_id"}))
-    . qq| | |;
+  my $shipto;
+  if (scalar @values > 1) {
+    $shipto = qq|
+    
+      | | . $locale->text('Shipping Address') . qq| | 
+      | . NTI($cgi->popup_menu('-name' => 'shipto_id', '-values' => \@values, '-style' => 'width: 250px',
+                                   '-labels' => \%labels, '-default' => $form->{"shipto_id"})). qq|
+       | |;
+  }
+
+  %labels = ();
+  @values = ();
+  foreach my $item (@{ $form->{"ALL_CURRENCIES"} }) {
+    push(@values, $item);
+    $labels{$item} = $item;
+  }
+
+  $form->{currency}        = $form->{defaultcurrency} unless $form->{currency};
+  my $currencies;
+  if (scalar @values) {
+    $currencies = qq|
+    
+      | | . $locale->text('Currency') . qq| | 
+      | . NTI($cgi->popup_menu('-name' => 'currency', '-default' => $form->{"currency"},
+                                   '-values' => \@values, '-labels' => \%labels)) . qq|
+       | 
+    
|;
+  }
 
   %labels = ();
   @values = ("");
@@ -394,63 +419,80 @@ sub form_header {
     push(@values, $item->{"id"});
     $labels{$item->{"id"}} = $item->{"projectnumber"};
   }
-  my $globalprojectnumber =
-    NTI($cgi->popup_menu('-name' => 'globalproject_id', '-values' => \@values,
-                         '-labels' => \%labels,
-                         '-default' => $form->{"globalproject_id"}));
+  my $globalprojectnumber = NTI($cgi->popup_menu('-name' => 'globalproject_id', '-values' => \@values,
+                                                 '-labels' => \%labels,
+                                                 '-default' => $form->{"globalproject_id"}));
 
-  # set option selected
-  foreach $item (qw(AR customer currency department employee)) {
-    $form->{"select$item"} =~ s/ selected//;
-    $form->{"select$item"} =~
-      s/option>\Q$form->{$item}\E/option selected>$form->{$item}/;
+  %labels = ();
+  @values = ();
+  foreach my $item (@{ $form->{ALL_SALESMEN} }) {
+    push(@values, $item->{id});
+    $labels{$item->{id}} = $item->{name} ne "" ? $item->{name} : $item->{login};
   }
 
-  #quote customer Bug 133
-  $form->{selectcustomer} = $form->quote($form->{selectcustomer});
-  
-  if (($form->{creditlimit} != 0) && ($form->{creditremaining} < 0) && !$form->{update}) {
-    $creditwarning = 1;
+  $salesman =
+    qq| | | . $locale->text('Salesman') . qq| | 
+         | . NTI($cgi->popup_menu('-name' => 'salesman_id', '-values' => \@values, '-labels' => \%labels,
+                                      '-default' => $form->{salesman_id} ? $form->{salesman_id} : $form->{employee_id})) . qq|
+          | 
+       
|;
+
+  %labels = ();
+  @values = ();
+  foreach my $item (@{ $form->{"ALL_TAXZONES"} }) {
+    push(@values, $item->{"id"});
+    $labels{$item->{"id"}} = $item->{"description"};
+  }
+
+  if (!$form->{"id"}) {
+    $taxzone = qq|
+    
+      | | . $locale->text('Steuersatz') . qq| | 
+      | . NTI($cgi->popup_menu('-name' => 'taxzone_id', '-default' => $form->{"taxzone_id"},
+                                   '-values' => \@values, '-labels' => \%labels, '-style' => 'width: 250px',)) . qq|
+       | 
+    
|;
+
   } else {
-    $creditwarning = 0;
+    $taxzone = qq|
+    
+      | | . $locale->text('Steuersatz') . qq| | 
+      
+        
+        | . H($labels{$form->{"taxzone_id"}}) . qq|
+       | 
+    
|;
+  }
+
+  # set option selected
+  foreach $item (qw(AR customer currency department employee)) {
+    $form->{"select$item"} =~ s/ selected//;
+    $form->{"select$item"} =~ s/option>\Q$form->{$item}\E/option selected>$form->{$item}/;
   }
 
-  $form->{exchangerate} =
-    $form->format_amount(\%myconfig, $form->{exchangerate});
+  $creditwarning = (($form->{creditlimit} != 0) && ($form->{creditremaining} < 0) && !$form->{update}) ? 1 : 0;
 
-  $form->{creditlimit} =
-    $form->format_amount(\%myconfig, $form->{creditlimit}, 0, "0");
-  $form->{creditremaining} =
-    $form->format_amount(\%myconfig, $form->{creditremaining}, 0, "0");
+  $form->{exchangerate}    = $form->format_amount(\%myconfig, $form->{exchangerate});
+  $form->{creditlimit}     = $form->format_amount(\%myconfig, $form->{creditlimit}, 0, "0");
+  $form->{creditremaining} = $form->format_amount(\%myconfig, $form->{creditremaining}, 0, "0");
 
   $exchangerate = "";
   if ($form->{currency} ne $form->{defaultcurrency}) {
     if ($form->{forex}) {
-      $exchangerate .=
-          qq||
-        . $locale->text('Exchangerate')
-        . qq| | $form->{exchangerate}{exchangerate}> | |;
+      $exchangerate .= qq|| . $locale->text('Exchangerate') . qq| | 
+                          $form->{exchangerate} | |;
     } else {
-      $exchangerate .=
-          qq||
-        . $locale->text('Exchangerate')
-        . qq| | {exchangerate}> | |;
+      $exchangerate .= qq|| . $locale->text('Exchangerate') . qq| | 
+                           | |;
     }
   }
-  $exchangerate .= qq|
-{forex}>
-|;
-
-  $customer =
-    ($form->{selectcustomer})
-    ? qq|\n|
-    : qq||;
+  $exchangerate .= qq|\n\n|;
 
   $department = qq|
               
 	        | | . $locale->text('Department') . qq| | 
-		
-		
+		 | 
+                  
 		 | 
 	      
 | if $form->{selectdepartment};
@@ -460,121 +502,87 @@ sub form_header {
   if ($form->{business}) {
     $business = qq|
 	      
-		| | . $locale->text('Business') . qq| | 
-		$form->{business} | 
-		| . $locale->text('Trade Discount') . qq| | 
-		|
+           | | . $locale->text('Customer type') . qq| | 
+          $form->{business}; | . $locale->text('Trade Discount') . qq| |
       . $form->format_amount(\%myconfig, $form->{tradediscount} * 100)
       . qq| % | 
-	      
+        
 |;
   }
 
   if ($form->{max_dunning_level}) {
     $dunning = qq|
-	      
-                
-                
-                  
-		| | . $locale->text('Max. Dunning Level') . qq|: | 
-		$form->{max_dunning_level} | 
-		| . $locale->text('Dunning Amount') . qq|: | 
-		|
-      . $form->format_amount(\%myconfig, $form->{dunning_amount},2)
-      . qq| | 
-	       
-               
-              | 
-            
+      
+        | | . $locale->text('Max. Dunning Level') . qq|: | 
+        
+          $form->{max_dunning_level};
+          | . $locale->text('Dunning Amount') . qq|: |
+        . $form->format_amount(\%myconfig, $form->{dunning_amount},2)
+        . qq|
+         | 
+      
 |;
   }
 
   $form->{fokus} = "invoice.customer";
 
   # use JavaScript Calendar or not
-  $form->{jsscript} = $jscalendar;
+  $form->{jsscript} = 1;
   $jsscript = "";
   if ($form->{type} eq "credit_note") {
-    if ($form->{jsscript}) {
-  
-      # with JavaScript Calendar
-      $button1 = qq|
-        {invdate}> | 
-        text('button') . qq|> | 
-        |;
-  
-      #write Trigger
-      $jsscript =
-        Form->write_trigger(\%myconfig,     "1",
-                            "invdate",      "BL",
-                            "trigger1");
-    } else {
-  
-      # without JavaScript Calendar
-      $button1 =
-        qq|{invdate}> | |;
-      $button2 =
-        qq|{duedate}> | |;
-    }
+    $button1 = qq|
+      
+        | |;
+
+    #write Trigger
+    $jsscript =
+      Form->write_trigger(\%myconfig,     "1",
+                          "invdate",      "BL",
+                          "trigger1");
   } else {
-    if ($form->{jsscript}) {
-  
-      # with JavaScript Calendar
-      $button1 = qq|
-        {invdate}> | 
-        text('button') . qq|> | 
-        |;
-      $button2 = qq|
-        {duedate}> | 
-        text('button') . qq|> | 
-      |;
-      $button3 = qq|
-        {deliverydate}> | 
-        text('button') . qq|> | 
+    $button1 = qq|
+      
+        | 
       |;
-  
-      #write Trigger
-      $jsscript =
-        Form->write_trigger(\%myconfig,     "3",
-                            "invdate",      "BL",
-                            "trigger1",     "duedate",
-                            "BL",           "trigger2",
-                            "deliverydate", "BL",
-                            "trigger3");
-    } else {
-  
-      # without JavaScript Calendar
-      $button1 =
-        qq|{invdate}> | |;
-      $button2 =
-        qq|{duedate}> | |;
-    }
-  }
-  if ($form->{resubmit} && ($form->{format} eq "html")) {
-    $onload =
-      qq|window.open('about:blank','Beleg'); document.invoice.target = 'Beleg';document.invoice.submit()|;
-  } elsif ($form->{resubmit}) {
-    $onload = qq|document.invoice.submit()|;
-  } else {
-    $onload = "fokus()";
+    $button2 = qq|
+      
+        | 
+    |;
+    $button3 = qq|
+      
+        | 
+    |;
+
+    #write Trigger
+    $jsscript =
+      Form->write_trigger(\%myconfig,     "3",
+                          "invdate",      "BL", "trigger1", 
+                          "duedate",      "BL", "trigger2",
+                          "deliverydate", "BL", "trigger3");
   }
 
   $credittext = $locale->text('Credit Limit exceeded!!!');
-  if ($creditwarning) {
-    $onload = qq|alert('$credittext')|;
-  }
+  $onload = ($form->{resubmit} && ($form->{format} eq "html")) ? qq|window.open('about:blank','Beleg'); document.invoice.target = 'Beleg';document.invoice.submit()|
+          : ($form->{resubmit})                                ? qq|document.invoice.submit()|
+          : ($creditwarning)                                   ? qq|alert('$credittext')|
+          :                                                      "focus()";
+  $onload .= qq|;setupDateFormat('|. $myconfig{dateformat} .qq|', '|. $locale->text("Falsches Datumsformat!") .qq|')|;
+  $onload .= qq|;setupPoints('|. $myconfig{numberformat} .qq|', '|. $locale->text("wrongformat") .qq|')|;
 
-  $form->{"javascript"} .= qq||;
+  $form->{javascript} .= qq||;
+  $form->{javascript} .= qq||;
 
   $jsscript .=
     $form->write_trigger(\%myconfig, 2,
                          "orddate", "BL", "trigger_orddate",
                          "quodate", "BL", "trigger_quodate");
-
+  # show history button js
+  $form->{javascript} .= qq||;
+  #/show history button js
   $form->header;
 
   print qq|
@@ -584,102 +592,69 @@ sub form_header {
 
 
 
-
 
-
 |;
@@ -1544,7 +1537,7 @@ sub credit_note {
   $form->{script} = 'is.pl';
   $script         = "is";
   $buysell        = 'buy';
-  
+
 
   # bo creates the id, reset it
   map { delete $form->{$_} }
@@ -1584,10 +1577,38 @@ sub credit_note {
 
 sub yes {
   $lxdebug->enter_sub();
-
-  $form->redirect($locale->text('Invoice deleted!'))
-    if (IS->delete_invoice(\%myconfig, \%$form, $spool));
+  if (IS->delete_invoice(\%myconfig, \%$form, $spool)) {
+    # saving the history
+  	if(!exists $form->{addition}) {
+    $form->{snumbers} = qq|invnumber_| . $form->{invnumber};
+  	  $form->{addition} = "DELETED";
+  	  $form->save_history($form->dbconnect(\%myconfig));
+    }
+    # /saving the history
+    $form->redirect($locale->text('Invoice deleted!'));
+  }
   $form->error($locale->text('Cannot delete invoice!'));
 
   $lxdebug->leave_sub();
 }
+
+sub e_mail {
+  $lxdebug->enter_sub();
+
+  if (!$form->{id}) {
+    $print_post = 1;
+
+    my $saved_form = save_form();
+
+    post();
+
+    my %saved_vars;
+    map({ $saved_vars{$_} = $form->{$_}; } qw(id invnumber));
+    restore_form($saved_form);
+    map({ $form->{$_} = $saved_vars{$_}; } qw(id invnumber));
+  }
+
+  edit_e_mail();
+
+  $lxdebug->leave_sub();
+}