]> wagnertech.de Git - mfinanz.git/blobdiff - bin/mozilla/oe.pl
Verknüpfungen zwischen Angeboten, Aufträgen, Lieferscheinen, Rechnungen in einer...
[mfinanz.git] / bin / mozilla / oe.pl
index 95376da61cbe045ce3f2ed60cb0c344da2ae841a..6c2569b6f84abcd507432efdbb4745c5aff01860 100644 (file)
@@ -33,6 +33,7 @@
 
 use POSIX qw(strftime);
 
+use SL::DO;
 use SL::FU;
 use SL::OE;
 use SL::IR;
@@ -171,11 +172,20 @@ sub edit {
   set_headings("edit");
 
   &order_links;
+
+  $form->{rowcount} = 0;
+  foreach $ref (@{ $form->{form_details} }) {
+    $form->{rowcount}++;
+    map { $form->{"${_}_$form->{rowcount}"} = $ref->{$_} } keys %{$ref};
+  }
+
   &prepare_order;
+
   if ($form->{print_and_save}) {
     $form->{language_id} = $language_id;
     $form->{printer_id} = $printer_id;
   }
+
   &display_form;
 
   $lxdebug->leave_sub();
@@ -200,51 +210,31 @@ sub order_links {
   # if multiple rowcounts (== collective order) then check if the
   # there were more than one customer (in that case OE::retrieve removes
   # the content from the field)
-  if (   $form->{rowcount}          && $form->{type} eq 'sales_order'
-      && defined $form->{customer}  && $form->{customer} eq '') {
-    $form->error($locale->text('Collective Orders only work for orders from one customer!'));
-  }
+  $form->error($locale->text('Collective Orders only work for orders from one customer!'))
+    if          $form->{rowcount}  && $form->{type}     eq 'sales_order'
+     && defined $form->{customer}  && $form->{customer} eq '';
 
   $form->{"$form->{vc}_id"} ||= $form->{"all_$form->{vc}"}->[0]->{id} if $form->{"all_$form->{vc}"};
 
-  $payment_id     = $form->{payment_id}  if $form->{payment_id};
-  $language_id    = $form->{language_id} if $form->{language_id};
-  $taxzone_id     = $form->{taxzone_id}  if $form->{taxzone_id};
-  $salesman_id    = $form->{salesman_id} if $editing;
-  $taxincluded    = $form->{taxincluded};
-  $cp_id          = $form->{cp_id};
-  $intnotes       = $form->{intnotes};
+  $form->backup_vars(qw(payment_id language_id taxzone_id salesman_id taxincluded cp_id intnotes));
   $form->{shipto} = 1 if $form->{id};
 
   # get customer / vendor
   IR->get_vendor(\%myconfig, \%$form)   if $form->{type} =~ /(purchase_order|request_quotation)/;
   IS->get_customer(\%myconfig, \%$form) if $form->{type} =~ /sales_(order|quotation)/;
 
-  $form->{cp_id}       = $cp_id;
-  $form->{payment_id}  = $payment_id  if $payment_id;
-  $form->{language_id} = $language_id if $language_id;
-  $form->{taxzone_id}  = $taxzone_id  if $taxzone_id;
-  $form->{intnotes}    = $intnotes    if $intnotes;
-  $form->{taxincluded} = $taxincluded if $form->{id};
-  $form->{salesman_id} = $salesman_id if $editing;
+  $form->restore_vars(qw(payment_id language_id taxzone_id intnotes cp_id));
+  $form->restore_vars(qw(taxincluded)) if $form->{id};
+  $form->restore_vars(qw(salesman_id)) if $editing;
   $form->{forex}       = $form->{exchangerate};
   $form->{employee}    = "$form->{employee}--$form->{employee_id}";
 
-  # build vendor/customer drop down
-  ($form->{ $form->{vc} }) = split /--/, $form->{ $form->{vc} };
-  $form->{"old$form->{vc}"} = qq|$form->{$form->{vc}}--$form->{"$form->{vc}_id"}|;
-
+  # build vendor/customer drop down comatibility... don't ask
   if (@{ $form->{"all_$form->{vc}"} }) {
-    map { $_->{name} = $form->quote($_->{name}) } @{ $form->{"all_$form->{vc}"} };
-    $form->{ $form->{vc} }       = qq|$form->{$form->{vc}}--$form->{"$form->{vc}_id"}|;
-    $form->{"select$form->{vc}"} = join "\n", map "<option>$_->{name}--$_->{id}</option>", @{ $form->{"all_$form->{vc}"} };
-  }
-
-  # departments
-  if (@{ $form->{all_departments} }) {
-    $form->{department}       = "$form->{department}--$form->{department_id}";
-    $form->{selectdepartment} = join "\n", "<option>", map "<option>$_->{description}--$_->{id}</option>", @{ $form->{all_departments} };
+    $form->{"select$form->{vc}"} = 1;
+    $form->{$form->{vc}}         = qq|$form->{$form->{vc}}--$form->{"$form->{vc}_id"}|;
   }
+  $form->{"old$form->{vc}"}    = $form->{$form->{vc}};
 
   $lxdebug->leave_sub();
 }
@@ -254,15 +244,10 @@ sub prepare_order {
 
   check_oe_access();
 
-  $form->{formname} = $form->{type} unless $form->{formname};
+  $form->{formname} ||= $form->{type};
 
-  my $i = 0;
-  foreach $ref (@{ $form->{form_details} }) {
-    $form->{rowcount} = ++$i;
-    map { $form->{"${_}_$i"} = $ref->{$_} } keys %{$ref};
-  }
   for my $i (1 .. $form->{rowcount}) {
-    $form->{"reqdate_$i"}   = $form->{"deliverydate_$i"} unless $form->{"reqdate_$i"};
+    $form->{"reqdate_$i"} ||= $form->{"deliverydate_$i"};
     $form->{"discount_$i"}  = $form->format_amount(\%myconfig, $form->{"discount_$i"} * ($form->{id} ? 100 : 1));
     $form->{"sellprice_$i"} = $form->format_amount(\%myconfig, $form->{"sellprice_$i"});
     $form->{"qty_$i"}       = $form->format_amount(\%myconfig, $form->{"qty_$i"});
@@ -280,9 +265,6 @@ sub form_header {
   # Container for template variables. Unfortunately this has to be visible in form_footer too, so not my.
   our %TMPL_VAR = ();
 
-  $form->{employee_id} = $form->{old_employee_id} if $form->{old_employee_id};
-  $form->{salesman_id} = $form->{old_salesman_id} if $form->{old_salesman_id};
-
   $form->{defaultcurrency} = $form->get_default_currency(\%myconfig);
 
   $form->{employee_id} = $form->{old_employee_id} if $form->{old_employee_id};
@@ -339,14 +321,16 @@ sub form_header {
                    "taxzones"      => "ALL_TAXZONES",
                    "payments"      => "ALL_PAYMENTS",
                    "currencies"    => "ALL_CURRENCIES",
+                   "departments"   => "ALL_DEPARTMENTS",
                    $vc             => { key   => "ALL_" . uc($vc),
                                         limit => $myconfig{vclimit} + 1 },
                    "price_factors" => "ALL_PRICE_FACTORS");
 
   # label subs
   $TMPL_VAR{sales_employee_labels} = sub { $_[0]->{name} || $_[0]->{login} };
-  $TMPL_VAR{shipto_labels} = sub { join "; ", grep { $_ } map { $_[0]->{"shipto${_}" } } qw(name department_1 street city) };
-  $TMPL_VAR{contact_labels} = sub { $_[0]->{"cp_name"} . ($_[0]->{cp_abteilung} ? " ($_[0]->{cp_abteilung})" : "") };
+  $TMPL_VAR{shipto_labels}         = sub { join "; ", grep { $_ } map { $_[0]->{"shipto${_}" } } qw(name department_1 street city) };
+  $TMPL_VAR{contact_labels}        = sub { join(', ', $_[0]->{"cp_name"}, $_[0]->{"cp_givenname"}) . ($_[0]->{cp_abteilung} ? " ($_[0]->{cp_abteilung})" : "") };
+  $TMPL_VAR{department_labels}     = sub { "$_[0]->{description}--$_[0]->{id}" }; 
 
   # vendor/customer
   $TMPL_VAR{vc_keys} = sub { "$_[0]->{name}--$_[0]->{id}" };
@@ -360,7 +344,7 @@ sub form_header {
   @values = map { $_ } @{ $form->{ALL_CURRENCIES} };
   %labels = map { $_ => $_ } @{ $form->{ALL_CURRENCIES} };
   $form->{currency}            = $form->{defaultcurrency} unless $form->{currency};
-  $TMPL_VAR{show_exchangerate} = $form->{currency} ne $form->{defaultcurrency} && $form->{exchangerate};
+  $TMPL_VAR{show_exchangerate} = $form->{currency} ne $form->{defaultcurrency};
   $TMPL_VAR{currencies}        = NTI($cgi->popup_menu('-name' => 'currency', '-default' => $form->{"currency"},
                                                       '-values' => \@values, '-labels' => \%labels)) if scalar @values;
   push @custom_hiddens, "forex";
@@ -412,7 +396,7 @@ sub form_header {
         max_dunning_level dunning_amount shiptoname shiptostreet shiptozipcode
         shiptocity shiptocountry shiptocontact shiptophone shiptofax
         shiptodepartment_1 shiptodepartment_2 shiptoemail
-        message email subject cc bcc taxpart taxservice taxaccounts),
+        message email subject cc bcc taxpart taxservice taxaccounts cursor_fokus),
         @custom_hiddens,
         map { $_.'_rate', $_.'_description' } split / /, $form->{taxaccounts} ];  # deleted: discount
 
@@ -516,8 +500,8 @@ sub update {
   
   $buysell              = 'buy';
   $buysell              = 'sell' if ($form->{vc} eq 'vendor');
-  $form->{exchangerate} = $exchangerate if 
-    $form->{forex} = $exchangerate = $form->check_exchangerate(\%myconfig, $form->{currency}, $form->{transdate}, $buysell);
+  $form->{forex}        = $form->check_exchangerate(\%myconfig, $form->{currency}, $form->{transdate}, $buysell);
+  $form->{exchangerate} = $form->{forex} if $form->{forex};
 
   $exchangerate = $form->{exchangerate} || 1;
 
@@ -1518,15 +1502,8 @@ sub invoice {
   &invoice_links;
 
   $form->{currency}     = $currency;
-  $form->{exchangerate} = "";
-  $form->{forex}        = "";
-  $form->{exchangerate} = $exchangerate
-    if (
-        $form->{forex} = (
-                    $exchangerate =
-                      $form->check_exchangerate(
-                      \%myconfig, $form->{currency}, $form->{invdate}, $buysell
-                      )));
+  $form->{forex}        = $form->check_exchangerate( \%myconfig, $form->{currency}, $form->{invdate}, $buysell);
+  $form->{exchangerate} = $form->{forex} || '';
 
   $form->{creditremaining} -= ($form->{oldinvtotal} - $form->{ordtotal});
 
@@ -1837,7 +1814,8 @@ sub sales_order {
     delete($form->{ordnumber});
   }
 
-  $form->{cp_id} *= 1;
+  $form->{cp_id}  *= 1;
+  $form->{oe_ids}  = $form->{id};
 
   $form->{title} = $locale->text('Add Sales Order');
   $form->{vc}    = "customer";
@@ -1857,30 +1835,29 @@ sub poso {
   $form->{transdate} = $form->current_date(\%myconfig);
   delete $form->{duedate};
 
-  $form->{closed} = 0;
+  $form->{closed}          = 0;
 
   $form->{old_employee_id} = $form->{employee_id};
   $form->{old_salesman_id} = $form->{salesman_id};
 
   # reset
-  map { delete $form->{$_} }
-    qw(id subject message cc bcc printed emailed queued customer vendor creditlimit creditremaining discount tradediscount oldinvtotal);
+  map { delete $form->{$_} } qw(id subject message cc bcc printed emailed queued customer vendor creditlimit creditremaining discount tradediscount oldinvtotal);
 
   for $i (1 .. $form->{rowcount}) {
-    map({ $form->{"${_}_${i}"} = $form->parse_amount(\%myconfig,
-                                                     $form->{"${_}_${i}"})
-            if ($form->{"${_}_${i}"}) }
-        qw(ship qty sellprice listprice basefactor));
+    map { $form->{"${_}_${i}"} = $form->parse_amount(\%myconfig, $form->{"${_}_${i}"}) if ($form->{"${_}_${i}"}) } qw(ship qty sellprice listprice basefactor);
   }
 
+  my %saved_vars = map { $_ => $form->{$_} } grep { $form->{$_} } qw(currency);
+
   &order_links;
 
+  map { $form->{$_} = $saved_vars{$_} } keys %saved_vars;
+
   &prepare_order;
 
   # format amounts
   for $i (1 .. $form->{rowcount} - 1) {
-    map { $form->{"${_}_$i"} =~ s/\"/&quot;/g }
-      qw(partnumber description unit);
+    map { $form->{"${_}_$i"} =~ s/\"/&quot;/g } qw(partnumber description unit);
   }
 
   &update;
@@ -1907,6 +1884,7 @@ sub delivery_order {
   require "bin/mozilla/do.pl";
 
   $form->{cp_id}           *= 1;
+  $form->{oe_ids}           = $form->{id};
   $form->{transdate}        = $form->current_date(\%myconfig);
   delete $form->{duedate};