Anzeige der bereits gelieferten Menge in Aufträgen im Ein- und Verkauf.
authorMoritz Bunkus <m.bunkus@linet-services.de>
Tue, 10 Jun 2008 15:28:39 +0000 (15:28 +0000)
committerMoritz Bunkus <m.bunkus@linet-services.de>
Tue, 10 Jun 2008 15:28:39 +0000 (15:28 +0000)
12 files changed:
SL/DO.pm
bin/mozilla/io.pl
bin/mozilla/oe.pl
locale/de/dn
locale/de/do
locale/de/ic
locale/de/io
locale/de/ir
locale/de/is
locale/de/login
locale/de/oe
locale/de/todo

index 2e61270..7f547f0 100644 (file)
--- a/SL/DO.pm
+++ b/SL/DO.pm
@@ -161,6 +161,7 @@ sub transactions {
     my $sth = prepare_query($form, $dbh, $query);
 
     foreach my $dord (@{ $form->{DO} }) {
+      next unless ($dord->{ordnumber});
       do_statement($form, $sth, $query, $dord->{ordnumber});
       ($dord->{oe_id}) = $sth->fetchrow_array();
     }
@@ -903,4 +904,46 @@ sub transfer_in_out {
   $main::lxdebug->leave_sub();
 }
 
+sub get_shipped_qty {
+  $main::lxdebug->enter_sub();
+
+  my $self     = shift;
+  my %params   = @_;
+
+  Common::check_params(\%params, qw(type ordnumber));
+
+  my $myconfig = \%main::myconfig;
+  my $form     = $main::form;
+
+  my $dbh      = $params{dbh} || $form->get_standard_dbh($myconfig);
+
+  my $notsales = $params{type} eq 'sales' ? '' : 'NOT';
+
+  my $query    =
+    qq|SELECT doi.parts_id, doi.qty, doi.unit, p.unit AS partunit
+       FROM delivery_order_items doi
+       LEFT JOIN delivery_orders o ON (doi.delivery_order_id = o.id)
+       LEFT JOIN parts p ON (doi.parts_id = p.id)
+       WHERE ($notsales o.is_sales)
+         AND (o.ordnumber = ?)|;
+
+  my %ship      = ();
+  my $entries   = selectall_hashref_query($form, $dbh, $query, $params{ordnumber});
+  my $all_units = AM->retrieve_all_units();
+
+  foreach my $entry (@{ $entries }) {
+    $entry->{qty} *= $all_units->{$entry->{unit}}->{factor} / $all_units->{$entry->{partunit}}->{factor};
+
+    if (!$ship{$entry->{parts_id}}) {
+      $ship{$entry->{parts_id}} = $entry;
+    } else {
+      $ship{$entry->{parts_id}}->{qty} += $entry->{qty};
+    }
+  }
+
+  $main::lxdebug->leave_sub();
+
+  return %ship;
+}
+
 1;
index eb9ca0f..f5e3fdc 100644 (file)
@@ -35,7 +35,7 @@
 
 use CGI;
 use CGI::Ajax;
-use List::Util qw(max first);
+use List::Util qw(min max first);
 
 use SL::CVar;
 use SL::Common;
@@ -111,6 +111,7 @@ sub display_row {
   my $is_purchase        = (first { $_ eq $form->{type} } qw(request_quotation purchase_order purchase_delivery_order)) || ($form->{script} eq 'ir.pl');
   my $show_min_order_qty =  first { $_ eq $form->{type} } qw(request_quotation purchase_order);
   my $is_delivery_order  = $form->{type} =~ /_delivery_order$/;
+  my $is_s_p_order       = (first { $_ eq $form->{type} } qw(sales_order purchase_order));
 
   if ($is_delivery_order) {
     $readonly             = ' readonly' if ($form->{closed});
@@ -132,8 +133,7 @@ sub display_row {
     {  id => 'runningnumber', width => 5,     value => $locale->text('No.'),                  display => 1, },
     {  id => 'partnumber',    width => 8,     value => $locale->text('Number'),               display => 1, },
     {  id => 'description',   width => 30,    value => $locale->text('Part Description'),     display => 1, },
-    {  id => 'ship',          width => 5,     value => ($form->{type} eq 'purchase_order' ? $locale->text('Ship rcvd') : $locale->text('Ship')),                 
-       display => $form->{type} =~ /sales_order/ || ($form->{type} =~ /purchase_order/ && !($lizenzen && $form->{vc} eq "customer")) , },
+    {  id => 'ship',          width => 5,     value => $locale->text('Delivered'),            display => $is_s_p_order, },
     {  id => 'qty',           width => 5,     value => $locale->text('Qty'),                  display => 1, },
     {  id => 'price_factor',  width => 5,     value => $locale->text('Price Factor'),         display => !$is_delivery_order, },
     {  id => 'unit',          width => 5,     value => $locale->text('Unit'),                 display => 1, },
@@ -188,11 +188,14 @@ sub display_row {
     $projectnumber_labels{$item->{"id"}} = $item->{"projectnumber"};
   }
 
+  _update_part_information();
+  _update_ship() if ($is_s_p_order);
+
   # rows
   for $i (1 .. $numrows) {
 
     # undo formatting
-    map { $form->{"${_}_$i"} = $form->parse_amount(\%myconfig, $form->{"${_}_$i"}) } qw(qty ship discount sellprice price_new price_old) unless ($form->{simple_save});
+    map { $form->{"${_}_$i"} = $form->parse_amount(\%myconfig, $form->{"${_}_$i"}) } qw(qty discount sellprice price_new price_old) unless ($form->{simple_save});
 
 # unit begin
     $form->{"unit_old_$i"}      ||= $form->{"unit_$i"};
@@ -250,7 +253,9 @@ sub display_row {
     $column_data{qty} .= $cgi->button(-onclick => "calculate_qty_selection_window('qty_$i','alu_$i', 'formel_$i', $i)", -value => $locale->text('*/'))
                        . $cgi->hidden(-name => "formel_$i", -value => $form->{"formel_$i"}) . $cgi->hidden("-name" => "alu_$i", "-value" => $form->{"alu_$i"})
       if $form->{"formel_$i"};
-    $column_data{ship} = $cgi->textfield(-name => "ship_$i", -size => 5, -value => $form->format_amount(\%myconfig, $form->{"ship_$i"}));
+    $column_data{ship} = !$form->{"id_$i"} ? '' : $form->format_amount_units('amount'     => $form->{"ship_$i"} * 1,
+                                                                             'part_unit'  => $form->{"partunit_$i"},
+                                                                             'max_places' => 2,);
 
     # build in drop down list for pricesgroups
     if ($form->{"prices_$i"}) {
@@ -1844,3 +1849,66 @@ sub set_duedate {
   $lxdebug->leave_sub();
 }
 
+sub _update_part_information {
+  $lxdebug->enter_sub();
+
+  my %part_information = IC->get_basic_part_info('id'        => [ grep { $_ } map { $form->{"id_${_}"} } (1..$form->{rowcount}) ],
+                                                 'vendor_id' => $form->{vendor_id});
+
+  $form->{PART_INFORMATION} = \%part_information;
+
+  foreach my $i (1..$form->{rowcount}) {
+    next unless ($form->{"id_${i}"});
+
+    my $info                 = $form->{PART_INFORMATION}->{$form->{"id_${i}"}} || { };
+    $form->{"partunit_${i}"} = $info->{unit};
+  }
+
+  $lxdebug->leave_sub();
+}
+
+sub _update_ship {
+  $lxdebug->enter_sub();
+
+  if (!$form->{ordnumber}) {
+    map { $form->{"ship_$_"} = 0 } (1..$form->{rowcount});
+    $lxdebug->leave_sub();
+    return;
+  }
+
+  AM->retrieve_all_units();
+
+  my %ship = DO->get_shipped_qty('type'      => ($form->{type} eq 'purchase_order') ? 'purchase' : 'sales',
+                                 'ordnumber' => $form->{ordnumber},);
+
+  foreach my $i (1..$form->{rowcount}) {
+    next unless ($form->{"id_${i}"});
+
+    $form->{"ship_$i"} = 0;
+
+    my $ship_entry = $ship{$form->{"id_$i"}};
+
+    next if (!$ship_entry || ($ship_entry->{qty} <= 0));
+
+    my $rowqty =
+      $form->parse_amount(\%myconfig, $form->{"qty_$i"})
+      * $all_units->{$form->{"unit_$i"}}->{factor}
+      / $all_units->{$form->{"partunit_$i"}}->{factor};
+
+    $form->{"ship_$i"}  = min($rowqty, $ship_entry->{qty});
+    $ship_entry->{qty} -= $form->{"ship_$i"};
+  }
+
+  foreach my $i (1..$form->{rowcount}) {
+    next unless ($form->{"id_${i}"});
+
+    my $ship_entry = $ship{$form->{"id_$i"}};
+
+    next if (!$ship_entry || ($ship_entry->{qty} <= 0.01));
+
+    $form->{"ship_$i"} += $ship_entry->{qty};
+    $ship_entry->{qty}  = 0;
+  }
+
+  $lxdebug->leave_sub();
+}
index 93f28f0..d121ae9 100644 (file)
@@ -33,6 +33,7 @@
 
 use POSIX qw(strftime);
 
+use SL::DO;
 use SL::FU;
 use SL::OE;
 use SL::IR;
index b25e507..152f9ff 100644 (file)
@@ -65,6 +65,7 @@ $self->{texts} = {
   'Date'                        => 'Datum',
   'Dec'                         => 'Dez',
   'December'                    => 'Dezember',
+  'Delivered'                   => 'Geliefert',
   'Delivery Date'               => 'Lieferdatum',
   'Delivery Order'              => 'Lieferschein',
   'Department'                  => 'Abteilung',
@@ -209,8 +210,6 @@ $self->{texts} = {
   'September'                   => 'September',
   'Serial No.'                  => 'Seriennummer',
   'Set eMail text'              => 'eMail Text eingeben',
-  'Ship'                        => 'Lagerausgang',
-  'Ship rcvd'                   => 'Lagereingang',
   'Ship to'                     => 'Lieferadresse',
   'Shipping Address'            => 'Lieferadresse',
   'Start Dunning Process'       => 'Mahnprozess starten',
@@ -282,6 +281,8 @@ $self->{subs} = {
   'NTI'                         => 'NTI',
   'Q'                           => 'Q',
   '_check_io_auth'              => '_check_io_auth',
+  '_update_part_information'    => '_update_part_information',
+  '_update_ship'                => '_update_ship',
   'add'                         => 'add',
   'build_std_url'               => 'build_std_url',
   'calculate_qty'               => 'calculate_qty',
index 0e7d3d9..5b93876 100644 (file)
@@ -302,6 +302,8 @@ $self->{subs} = {
   'NTI'                         => 'NTI',
   'Q'                           => 'Q',
   '_check_io_auth'              => '_check_io_auth',
+  '_update_part_information'    => '_update_part_information',
+  '_update_ship'                => '_update_ship',
   'add'                         => 'add',
   'build_std_url'               => 'build_std_url',
   'calculate_qty'               => 'calculate_qty',
index 9f77e79..fa8b369 100644 (file)
@@ -74,6 +74,7 @@ $self->{texts} = {
   'Dec'                         => 'Dez',
   'December'                    => 'Dezember',
   'Delete'                      => 'Löschen',
+  'Delivered'                   => 'Geliefert',
   'Delivery Date'               => 'Lieferdatum',
   'Delivery Order'              => 'Lieferschein',
   'Department'                  => 'Abteilung',
@@ -333,6 +334,8 @@ $self->{subs} = {
   'NTI'                         => 'NTI',
   'Q'                           => 'Q',
   '_check_io_auth'              => '_check_io_auth',
+  '_update_part_information'    => '_update_part_information',
+  '_update_ship'                => '_update_ship',
   'acc_menu'                    => 'acc_menu',
   'add'                         => 'add',
   'addtop100'                   => 'addtop100',
index 81aa77a..e995b15 100644 (file)
@@ -58,6 +58,7 @@ $self->{texts} = {
   'Date'                        => 'Datum',
   'Dec'                         => 'Dez',
   'December'                    => 'Dezember',
+  'Delivered'                   => 'Geliefert',
   'Delivery Date'               => 'Lieferdatum',
   'Delivery Order'              => 'Lieferschein',
   'Department'                  => 'Abteilung',
@@ -246,6 +247,8 @@ $self->{subs} = {
   'NTI'                         => 'NTI',
   'Q'                           => 'Q',
   '_check_io_auth'              => '_check_io_auth',
+  '_update_part_information'    => '_update_part_information',
+  '_update_ship'                => '_update_ship',
   'build_std_url'               => 'build_std_url',
   'calculate_qty'               => 'calculate_qty',
   'call_sub'                    => 'call_sub',
index 7991634..abe868e 100644 (file)
@@ -76,6 +76,7 @@ $self->{texts} = {
   'December'                    => 'Dezember',
   'Delete'                      => 'Löschen',
   'Delete drafts'               => 'Entwürfe löschen',
+  'Delivered'                   => 'Geliefert',
   'Delivery Date'               => 'Lieferdatum',
   'Delivery Order'              => 'Lieferschein',
   'Department'                  => 'Abteilung',
@@ -317,6 +318,8 @@ $self->{subs} = {
   'NTI'                         => 'NTI',
   'Q'                           => 'Q',
   '_check_io_auth'              => '_check_io_auth',
+  '_update_part_information'    => '_update_part_information',
+  '_update_ship'                => '_update_ship',
   'add'                         => 'add',
   'build_std_url'               => 'build_std_url',
   'calculate_qty'               => 'calculate_qty',
index a4592f8..78cb98c 100644 (file)
@@ -86,6 +86,7 @@ $self->{texts} = {
   'December'                    => 'Dezember',
   'Delete'                      => 'Löschen',
   'Delete drafts'               => 'Entwürfe löschen',
+  'Delivered'                   => 'Geliefert',
   'Delivery Date'               => 'Lieferdatum',
   'Delivery Order'              => 'Lieferschein',
   'Department'                  => 'Abteilung',
@@ -342,6 +343,8 @@ $self->{subs} = {
   'NTI'                         => 'NTI',
   'Q'                           => 'Q',
   '_check_io_auth'              => '_check_io_auth',
+  '_update_part_information'    => '_update_part_information',
+  '_update_ship'                => '_update_ship',
   'add'                         => 'add',
   'build_std_url'               => 'build_std_url',
   'calculate_qty'               => 'calculate_qty',
index 8db11e0..5b811b0 100644 (file)
@@ -388,6 +388,8 @@ $self->{subs} = {
   'Q'                           => 'Q',
   '_check_io_auth'              => '_check_io_auth',
   '_collect_links'              => '_collect_links',
+  '_update_part_information'    => '_update_part_information',
+  '_update_ship'                => '_update_ship',
   'add'                         => 'add',
   'backorder_exchangerate'      => 'backorder_exchangerate',
   'build_std_url'               => 'build_std_url',
index ad90ba9..983c24f 100644 (file)
@@ -354,6 +354,8 @@ $self->{subs} = {
   'NTI'                         => 'NTI',
   'Q'                           => 'Q',
   '_check_io_auth'              => '_check_io_auth',
+  '_update_part_information'    => '_update_part_information',
+  '_update_ship'                => '_update_ship',
   'add'                         => 'add',
   'backorder_exchangerate'      => 'backorder_exchangerate',
   'build_std_url'               => 'build_std_url',
index 0b93d9e..4189b2b 100644 (file)
@@ -381,6 +381,8 @@ $self->{subs} = {
   'Q'                           => 'Q',
   '_check_io_auth'              => '_check_io_auth',
   '_collect_links'              => '_collect_links',
+  '_update_part_information'    => '_update_part_information',
+  '_update_ship'                => '_update_ship',
   'add'                         => 'add',
   'backorder_exchangerate'      => 'backorder_exchangerate',
   'build_std_url'               => 'build_std_url',