Merge branch 'master' of vc.linet-services.de:public/lx-office-erp
authorJan Büren <jan@lx-office-hosting.de>
Tue, 10 Jan 2012 14:59:30 +0000 (15:59 +0100)
committerJan Büren <jan@lx-office-hosting.de>
Tue, 10 Jan 2012 14:59:30 +0000 (15:59 +0100)
1  2 
SL/DO.pm
SL/Form.pm
bin/mozilla/do.pl

diff --combined SL/DO.pm
+++ b/SL/DO.pm
@@@ -76,9 -76,10 +76,9 @@@ sub transactions 
  
    push @where, ($form->{type} eq 'sales_delivery_order' ? '' : 'NOT ') . qq|COALESCE(dord.is_sales, FALSE)|;
  
 -  my $department_id = (split /--/, $form->{department})[1];
 -  if ($department_id) {
 +  if ($form->{department_id}) {
      push @where,  qq|dord.department_id = ?|;
 -    push @values, conv_i($department_id);
 +    push @values, conv_i($form->{department_id});
    }
  
    if ($form->{project_id}) {
@@@ -251,9 -252,9 +251,9 @@@ sub save 
           id, delivery_order_id, parts_id, description, longdescription, qty, base_qty,
           sellprice, discount, unit, reqdate, project_id, serialnumber,
           ordnumber, transdate, cusordnumber,
-          lastcost, price_factor_id, price_factor, marge_price_factor)
+          lastcost, price_factor_id, price_factor, marge_price_factor, pricegroup_id)
         VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?,
-          (SELECT factor FROM price_factors WHERE id = ?), ?)|;
+          (SELECT factor FROM price_factors WHERE id = ?), ?, ?)|;
    my $h_item = prepare_query($form, $dbh, $q_item);
  
    my $q_item_stock =
                 $form->{"cusordnumber_$i"},
                 $form->{"lastcost_$i"},
                 conv_i($form->{"price_factor_id_$i"}), conv_i($form->{"price_factor_id_$i"}),
-                conv_i($form->{"marge_price_factor_$i"}));
+                conv_i($form->{"marge_price_factor_$i"}),
+                conv_i($form->{"pricegroup_id_$i"}));
      do_statement($form, $h_item, $q_item, @values);
  
      my $stock_info = DO->unpack_stock_information('packed' => $form->{"stock_${in_out}_$i"});
    $h_item->finish();
    $h_item_stock->finish();
  
 -  ($null, $form->{department_id}) = split(/--/, $form->{department});
  
    # save DO record
    $query =
@@@ -668,7 -671,7 +669,7 @@@ sub retrieve 
           doi.sellprice, doi.parts_id AS id, doi.unit, doi.discount, p.bin, p.notes AS partnotes,
           doi.reqdate, doi.project_id, doi.serialnumber, doi.lastcost,
           doi.ordnumber, doi.transdate, doi.cusordnumber, doi.longdescription,
-          doi.price_factor_id, doi.price_factor, doi.marge_price_factor,
+          doi.price_factor_id, doi.price_factor, doi.marge_price_factor, doi.pricegroup_id,
           pr.projectnumber, dord.transdate AS dord_transdate,
           pg.partsgroup
         FROM delivery_order_items doi
diff --combined SL/Form.pm
@@@ -1106,15 -1106,20 +1106,20 @@@ sub parse_template 
    close $temp_fh;
  
    if ($template->uses_temp_file() || $self->{media} eq 'email') {
-     $out = $self->{OUT};
-     $out_mode = $self->{OUT_MODE} || '>';
-     $self->{OUT} = "$self->{tmpfile}";
+     $out              = $self->{OUT};
+     $out_mode         = $self->{OUT_MODE} || '>';
+     $self->{OUT}      = "$self->{tmpfile}";
      $self->{OUT_MODE} = '>';
    }
  
    my $result;
+   my $command_formatter = sub {
+     my ($out_mode, $out) = @_;
+     return $out_mode eq '|-' ? SL::Template::create(type => 'ShellCommand', form => $self)->parse($out) : $out;
+   };
  
    if ($self->{OUT}) {
+     $self->{OUT} = $command_formatter->($self->{OUT_MODE}, $self->{OUT});
      open(OUT, $self->{OUT_MODE}, $self->{OUT}) or $self->error("error on opening $self->{OUT} with mode $self->{OUT_MODE} : $!");
    } else {
      *OUT = ($::dispatcher->get_standard_filehandles)[1];
  
        # if we send html or plain text inline
        if (($self->{format} eq 'html') && ($self->{sendmode} eq 'inline')) {
-         $mail->{contenttype} = "text/html";
-         $mail->{message}       =~ s/\r//g;
-         $mail->{message}       =~ s/\n/<br>\n/g;
-         $myconfig->{signature} =~ s/\n/<br>\n/g;
-         $mail->{message} .= "<br>\n-- <br>\n$myconfig->{signature}\n<br>";
+         $mail->{contenttype}    =  "text/html";
+         $mail->{message}        =~ s/\r//g;
+         $mail->{message}        =~ s/\n/<br>\n/g;
+         $myconfig->{signature}  =~ s/\n/<br>\n/g;
+         $mail->{message}       .=  "<br>\n-- <br>\n$myconfig->{signature}\n<br>";
  
          open(IN, "<", $self->{tmpfile})
            or $self->error($self->cleanup . "$self->{tmpfile} : $!");
-         while (<IN>) {
-           $mail->{message} .= $_;
-         }
+         $mail->{message} .= $_ while <IN>;
          close(IN);
  
        } else {
        #print(STDERR "OUT $self->{OUT}\n");
        for my $i (1 .. $self->{copies}) {
          if ($self->{OUT}) {
-           open OUT, $self->{OUT_MODE}, $self->{OUT} or $self->error($self->cleanup . "$self->{OUT} : $!");
+           $self->{OUT} = $command_formatter->($self->{OUT_MODE}, $self->{OUT});
+           open  OUT, $self->{OUT_MODE}, $self->{OUT} or $self->error($self->cleanup . "$self->{OUT} : $!");
            print OUT $_ while <IN>;
            close OUT;
-           seek IN, 0, 0;
+           seek  IN, 0, 0;
  
          } else {
            $self->{attachment_filename} = ($self->{attachment_filename})
@@@ -2509,7 -2512,7 +2512,7 @@@ sub get_name 
    return scalar(@{ $self->{name_list} });
  }
  
 -# the selection sub is used in the AR, AP, IS, IR and OE module
 +# the selection sub is used in the AR, AP, IS, IR, DO and OE module
  #
  sub all_vc {
    $main::lxdebug->enter_sub();
diff --combined bin/mozilla/do.pl
@@@ -40,6 -40,7 +40,6 @@@ use SL::IR
  use SL::IS;
  use SL::ReportGenerator;
  use SL::WH;
 -
  require "bin/mozilla/arap.pl";
  require "bin/mozilla/common.pl";
  require "bin/mozilla/invoice_io.pl";
@@@ -173,7 -174,7 +173,7 @@@ sub order_links 
    DO->retrieve('vc'  => $form->{vc},
                 'ids' => $form->{id});
  
-   $form->backup_vars(qw(payment_id language_id taxzone_id salesman_id taxincluded cp_id intnotes));
+   $form->backup_vars(qw(payment_id language_id taxzone_id salesman_id taxincluded cp_id intnotes currency));
    $form->{shipto} = 1 if $form->{id};
  
    # get customer / vendor
    }
  
    $form->restore_vars(qw(payment_id language_id taxzone_id intnotes cp_id));
+   $form->restore_vars(qw(currency)) if ($form->{id} || $form->{convert_from_oe_ids});
    $form->restore_vars(qw(taxincluded)) if $form->{id};
    $form->restore_vars(qw(salesman_id)) if $editing;
  
@@@ -300,17 -302,8 +301,17 @@@ sub form_header 
  
    $form->header();
    # Fix für Bug 1082 Erwartet wird: 'abteilungsNAME--abteilungsID'
 -  $form->{department} .= '--' . $form->{department_id};
 -
 +  # und Erweiterung für Bug 1760:
 +  # Das war leider nur ein Teil-Fix, da das Verhalten den 'Erneuern'-Knopf
 +  # nicht überlebt. Konsequent jetzt auf L umgestellt 
 +  #   $ perldoc SL::Template::Plugin::L
 +  # Daher entsprechend nur die Anpassung in form_header
 +  # und in DO.pm gemacht. 4 Testfälle:
 +  # department_id speichern                 | i.O.
 +  # department_id lesen                     | i.O.
 +  # department leer überlebt erneuern       | i.O.
 +  # department nicht leer überlebt erneuern | i.O.
 +  # $main::lxdebug->message(0, 'ABTEILUNGS ID in form?' . $form->{department_id});
    print $form->parse_html_template('do/form_header');
  
    $main::lxdebug->leave_sub();
@@@ -826,6 -819,13 +827,13 @@@ sub invoice 
  
    }
  
+   #  show pricegroup in newly loaded invoice when creating invoice from delivery order
+   for my $i (1 .. $form->{rowcount}) {
+     $form->{"sellprice_pg_$i"} = join /--/, $form->{"sellprice_$i"}, $form->{"pricegroup_id_$i"};
+   }
+   IS->get_pricegroups_for_parts(\%myconfig, \%$form);
+   set_pricegroup($_) for 1 .. $form->{rowcount};
    display_form();
  
    $main::lxdebug->leave_sub();
@@@ -924,6 -924,14 +932,14 @@@ sub invoice_multi 
  
    invoice_links();
    prepare_invoice();
+   #  show pricegroup in newly loaded invoice when creating invoice from delivery order
+   for my $i (1 .. $form->{rowcount}) {
+     $form->{"sellprice_pg_$i"} = join /--/, $form->{"sellprice_$i"}, $form->{"pricegroup_id_$i"};
+   }
+   IS->get_pricegroups_for_parts(\%myconfig, \%$form);
+   set_pricegroup($_) for 1 .. $form->{rowcount};
    display_form();
  
    $main::lxdebug->leave_sub();
@@@ -992,14 -1000,16 +1008,16 @@@ sub calculate_stock_in_out 
    my $in_out   = $form->{type} =~ /^sales/ ? 'out' : 'in';
    my $sinfo    = DO->unpack_stock_information('packed' => $form->{"stock_${in_out}_${i}"});
  
+   my $do_qty   = AM->sum_with_unit($::form->{"qty_$i"}, $::form->{"unit_$i"});
    my $sum      = AM->sum_with_unit(map { $_->{qty}, $_->{unit} } @{ $sinfo });
+   my $matches  = $do_qty == $sum;
  
    my $content  = $form->format_amount_units('amount'      => $sum * 1,
                                              'part_unit'   => $form->{"partunit_$i"},
                                              'amount_unit' => $all_units->{$form->{"partunit_$i"}}->{base_unit},
                                              'conv_units'  => 'convertible_not_smaller',
                                              'max_places'  => 2);
-   $content     = qq|<span id="stock_in_out_qty_display_${i}">${content}</span> <input type="button" onclick="open_stock_in_out_window('${in_out}', $i);" value="?">|;
+   $content     = qq|<span id="stock_in_out_qty_display_${i}">${content}</span><input type=hidden id='stock_in_out_qty_matches_$i' value='$matches'> <input type="button" onclick="open_stock_in_out_window('${in_out}', $i);" value="?">|;
  
    $main::lxdebug->leave_sub();
  
@@@ -1154,8 -1164,13 +1172,13 @@@ sub set_stock_in 
  
    _stock_in_out_set_qty_display($stock_info);
  
+   my $do_qty       = AM->sum_with_unit($::form->parse_amount(\%::myconfig, $::form->{do_qty}), $::form->{do_unit});
+   my $transfer_qty = AM->sum_with_unit(map { $_->{qty}, $_->{unit} } @{ $stock_info });
    $form->header();
-   print $form->parse_html_template('do/set_stock_in_out');
+   print $form->parse_html_template('do/set_stock_in_out', {
+     qty_matches => $do_qty == $transfer_qty,
+   });
  
    $main::lxdebug->leave_sub();
  }
@@@ -1249,8 -1264,13 +1272,13 @@@ sub set_stock_out 
    } else {
      _stock_in_out_set_qty_display($stock_info);
  
+     my $do_qty       = AM->sum_with_unit($::form->parse_amount(\%::myconfig, $::form->{do_qty}), $::form->{do_unit});
+     my $transfer_qty = AM->sum_with_unit(map { $_->{qty}, $_->{unit} } @{ $stock_info });
      $form->header();
-     print $form->parse_html_template('do/set_stock_in_out');
+     print $form->parse_html_template('do/set_stock_in_out', {
+       qty_matches => $do_qty == $transfer_qty,
+     });
    }
  
    $main::lxdebug->leave_sub();