Nach Buchen von Dialog-/Debitoren-/Kreditorenbuchungen Entwürfe nicht anzeigen
[kivitendo-erp.git] / bin / mozilla / ar.pl
index f03a74b..0e5ab85 100644 (file)
@@ -76,8 +76,6 @@ use strict;
 # $locale->text('Nov')
 # $locale->text('Dec')
 
-my $totalpaid;
-
 sub add {
   $main::lxdebug->enter_sub();
 
@@ -92,12 +90,12 @@ sub add {
   if(!exists $form->{addition} && ($form->{id} ne "")) {
     $form->{snumbers} = qq|invnumber_| . $form->{invnumber};
     $form->{addition} = "ADDED";
-    $form->save_history($form->dbconnect(\%myconfig));
+    $form->save_history;
   }
   # /saving the history
 
   $form->{title}    = "Add";
-  $form->{callback} = "ar.pl?action=add" unless $form->{callback};
+  $form->{callback} = "ar.pl?action=add&DONT_LOAD_DRAFT=1" unless $form->{callback};
 
   AR->get_transdate(\%myconfig, $form);
   $form->{initial_transdate} = $form->{transdate};
@@ -705,7 +703,7 @@ $jsscript
 ";
 
   my @triggers  = ();
-  my $totalpaid = 0;
+  $form->{totalpaid} = 0;
 
   $form->{paidaccounts}++ if ($form->{"paid_$form->{paidaccounts}"});
   for my $i (1 .. $form->{paidaccounts}) {
@@ -720,7 +718,7 @@ $jsscript
                            '-labels' => \%AR_paid_labels,
                            '-default' => $form->{"AR_paid_$i"}));
 
-    $totalpaid += $form->{"paid_$i"};
+    $form->{totalpaid} += $form->{"paid_$i"};
 
     # format amounts
     if ($form->{"paid_$i"}) {
@@ -778,14 +776,14 @@ $jsscript
     push(@triggers, "datepaid_$i", "BL", "trigger_datepaid_$i");
   }
 
-  my $paid_missing = $form->{invtotal_unformatted} - $totalpaid;
+  my $paid_missing = $form->{invtotal_unformatted} - $form->{totalpaid};
 
   print qq|
         <tr>
           <td></td>
           <td></td>
           <td align="center">| . $locale->text('Total') . qq|</td>
-          <td align="center">| . H($form->format_amount(\%myconfig, $totalpaid, 2)) . qq|</td>
+          <td align="center">| . H($form->format_amount(\%myconfig, $form->{totalpaid}, 2)) . qq|</td>
         </tr>
         <tr>
           <td></td>
@@ -862,7 +860,7 @@ $follow_ups_block
 
   # ToDO: - insert a global check for stornos, so that a storno is only possible a limited time after saving it
   print qq| <input class=submit type=submit name=action value="| . $locale->text('Storno') . qq|"> |
-    if ($form->{id} && !IS->has_storno(\%myconfig, $form, 'ar') && !IS->is_storno(\%myconfig, $form, 'ar') && (($totalpaid == 0) || ($totalpaid eq "")));
+    if ($form->{id} && !IS->has_storno(\%myconfig, $form, 'ar') && !IS->is_storno(\%myconfig, $form, 'ar') && (($form->{totalpaid} == 0) || ($form->{totalpaid} eq "")));
 
   if ($form->{id}) {
     if ($form->{radier}) {
@@ -984,10 +982,14 @@ sub update {
 
   $form->{invdate} = $form->{transdate};
 
-  my %saved_variables = map +( $_ => $form->{$_} ), qw(AR AR_amount_1 taxchart_1);
+  my %saved_variables = map +( $_ => $form->{$_} ), qw(AR AR_amount_1 taxchart_1 oldcustomer);
 
   &check_name("customer");
 
+  # check_name ruft get_customer auf, oldcustomer wird überschrieben, daher wird dies vorher gemerkt
+  # get_customer holt Bemerkungen als intnotes, für Debitorenbuchungen gibt es aber nur das Feld notes
+  $form->{notes} = $form->{intnotes} if $saved_variables{oldcustomer} ne $form->{customer};
+
   $form->{AR} = $saved_variables{AR};
   if ($saved_variables{AR_amount_1} =~ m/.--./) {
     map { $form->{$_} = $saved_variables{$_} } qw(AR_amount_1 taxchart_1);
@@ -1005,7 +1007,7 @@ sub update {
           $form->parse_amount(\%myconfig, $form->{"${_}_$i"})
       } qw(paid exchangerate);
 
-      $totalpaid += $form->{"paid_$i"};
+      $form->{totalpaid} += $form->{"paid_$i"};
 
       $form->{"forex_$i"}        = $form->check_exchangerate( \%myconfig, $form->{currency}, $form->{"datepaid_$i"}, 'buy');
       $form->{"exchangerate_$i"} = $form->{"forex_$i"} if $form->{"forex_$i"};
@@ -1013,10 +1015,10 @@ sub update {
   }
 
   $form->{creditremaining} -=
-    ($form->{invtotal} - $totalpaid + $form->{oldtotalpaid} -
+    ($form->{invtotal} - $form->{totalpaid} + $form->{oldtotalpaid} -
      $form->{oldinvtotal});
   $form->{oldinvtotal}  = $form->{invtotal};
-  $form->{oldtotalpaid} = $totalpaid;
+  $form->{oldtotalpaid} = $form->{totalpaid};
 
   &display_form;
 
@@ -1037,6 +1039,8 @@ sub post_payment {
 
   $form->{defaultcurrency} = $form->get_default_currency(\%myconfig);
 
+  my $invdate = $form->datetonum($form->{transdate}, \%myconfig);
+
   for my $i (1 .. $form->{paidaccounts}) {
 
     if ($form->parse_amount(\%myconfig, $form->{"paid_$i"})) {
@@ -1089,6 +1093,12 @@ sub post {
   $form->isblank("duedate",   $locale->text('Due Date missing!'));
   $form->isblank("customer",  $locale->text('Customer missing!'));
 
+  if ($myconfig{mandatory_departments} && !$form->{department}) {
+    $form->{saved_message} = $::locale->text('You have to specify a department.');
+    update();
+    exit;
+  }
+
   my $closedto  = $form->datetonum($form->{closedto},  \%myconfig);
   my $transdate = $form->datetonum($form->{transdate}, \%myconfig);
   $form->error($locale->text('Cannot post transaction for a closed period!')) if ($form->date_closed($form->{"transdate"}, \%myconfig));
@@ -1121,7 +1131,7 @@ sub post {
   my ($customer) = split /--/, $form->{customer};
   if ($form->{oldcustomer} ne "$customer--$form->{customer_id}") {
     update();
-    exit;
+    ::end_of_request();
   }
 
   $form->{AR}{receivables} = $form->{ARselected};
@@ -1134,7 +1144,7 @@ sub post {
   if(!exists $form->{addition} && $form->{id} ne "") {
     $form->{snumbers} = "invnumber_$form->{invnumber}";
     $form->{addition} = "POSTED";
-    $form->save_history($form->dbconnect(\%myconfig));
+    $form->save_history;
   }
   # /saving the history
   remove_draft() if $form->{remove_draft};
@@ -1157,7 +1167,7 @@ sub post_as_new {
   if(!exists $form->{addition} && $form->{id} ne "") {
     $form->{snumbers} = qq|invnumber_| . $form->{invnumber};
     $form->{addition} = "POSTED AS NEW";
-    $form->save_history($form->dbconnect(\%myconfig));
+    $form->save_history;
   }
   # /saving the history
   &post;
@@ -1240,7 +1250,7 @@ sub yes {
     if(!exists $form->{addition}) {
       $form->{snumbers} = qq|invnumber_| . $form->{invnumber};
       $form->{addition} = "DELETED";
-      $form->save_history($form->dbconnect(\%myconfig));
+      $form->save_history;
     }
     # /saving the history
     $form->redirect($locale->text('Transaction deleted!'));
@@ -1269,13 +1279,20 @@ sub search {
   $form->{title}    = $locale->text('AR Transactions');
   $form->{jsscript} = 1;
 
-  $form->get_lists("projects"     => { "key" => "ALL_PROJECTS", "all" => 1 },
-                   "departments"  => "ALL_DEPARTMENTS",
-                   "customers"    => "ALL_VC");
+  # Auch in Rechnungsübersicht nach Kundentyp filtern - jan
+  $form->get_lists("projects"       => { "key" => "ALL_PROJECTS", "all" => 1 },
+                   "departments"    => "ALL_DEPARTMENTS",
+                   "customers"      => "ALL_VC",
+                   "employees"    => "ALL_EMPLOYEES",
+                   "salesmen"     => "ALL_SALESMEN",
+                   "business_types" => "ALL_BUSINESS_TYPES");
+  $form->{SHOW_BUSINESS_TYPES} = scalar @{ $form->{ALL_BUSINESS_TYPES} } > 0;
 
   # constants and subs for template
   $form->{jsscript}  = 1;
   $form->{vc_keys}   = sub { "$_[0]->{name}--$_[0]->{id}" };
+  $form->{employee_labels} = sub { $_[0]->{"name"} || $_[0]->{"login"} };
+  $form->{salesman_labels} = $form->{employee_labels};
 
   $form->header;
   print $form->parse_html_template('ar/search', { %myconfig });
@@ -1392,6 +1409,9 @@ sub ar_transactions {
     my ($department) = split /--/, $form->{department};
     push @options, $locale->text('Department') . " : $department";
   }
+  if ($form->{department_id}) {
+    push @options, $locale->text('Department Id') . " : $form->{department_id}";
+  }
   if ($form->{invnumber}) {
     push @options, $locale->text('Invoice Number') . " : $form->{invnumber}";
   }
@@ -1424,6 +1444,7 @@ sub ar_transactions {
                        'attachment_basename'  => $locale->text('invoice_list') . strftime('_%Y%m%d', localtime time),
     );
   $report->set_options_from_form();
+  $locale->set_numberformat_wo_thousands_separator(\%myconfig) if lc($report->{options}->{output_format}) eq 'csv';
 
   # add sort and escape callback, this one we use for the add sub
   $form->{callback} = $href .= "&sort=$form->{sort}";
@@ -1514,7 +1535,7 @@ sub storno {
   if(!exists $form->{addition} && $form->{id} ne "") {
     $form->{snumbers} = "ordnumber_$form->{ordnumber}";
     $form->{addition} = "STORNO";
-    $form->save_history($form->dbconnect(\%myconfig));
+    $form->save_history;
   }
   # /saving the history