Projekt

Allgemein

Profil

« Zurück | Weiter » 

Revision b11b1a25

Von Tamino Steinert vor mehr als 1 Jahr hinzugefügt

  • ID b11b1a252dcb989869b2856df372c1fdb04ba92f
  • Vorgänger 1d122829
  • Nachfolger 32b9acd7

DispositionManager: Popup Artikeldetails überarbeitet

Unterschiede anzeigen:

SL/Controller/Part.pm
768 768
sub action_showdetails {
769 769
  my ($self, %params) = @_;
770 770

  
771
  eval {
772
      my @bindata;
773
      my $bins = SL::DB::Manager::Bin->get_all(with_objects => ['warehouse' ]);
774
      my %bins_by_id = map { $_->id => $_ } @$bins;
775
      my $inventories = SL::DB::Manager::Inventory->get_all(where => [ parts_id => $self->part->id],
776
                             with_objects => ['parts', 'trans_type' ], sort_by => 'bin_id ASC');
777
      foreach my $bin (@{ $bins }) {
778
          $bin->{qty} = 0;
779
      }
780

  
781
      foreach my $inv (@{ $inventories }) {
782
          my $bin = $bins_by_id{ $inv->bin_id };
783
          $bin->{qty}      += $inv->qty;
784
          $bin->{unit}     =  $inv->parts->unit;
785
          $bin->{reserved} =  defined $inv->reserve_for_id ? 1 : 0;
786
      }
787
      my $sum = 0;
788
      my $reserve_sum = 0;
789
      for my $bin (@{ $bins }) {
790
        push @bindata , {
791
          'warehouse'    => $bin->warehouse->forreserve ? $bin->warehouse->description.' (R)' : $bin->warehouse->description,
792
          'description'  => $bin->description,
793
          'qty'          => $bin->{qty},
794
          'unit'         => $bin->{unit},
795
        } if $bin->{qty} != 0;
796

  
797
        $sum += $bin->{qty};
798
        if($bin->warehouse->forreserve || defined $bin->warehouse->{reserve_for_id}){
799
          $reserve_sum += $bin->{qty};
800
        }
801
      }
802
      # Einfacher ? $sum = $self->part->onhand
803
      my $todate   = DateTime->now_local;
804
      my $fromdate = DateTime->now_local->add_duration(DateTime::Duration->new(years => -1));
805
      my $average  = 0;
806
      foreach my $inv (@{ $inventories }) {
807
        $average += abs($inv->qty) if $inv->shippingdate && $inv->trans_type->direction eq 'out' &&
808
          DateTime->compare($inv->shippingdate,$fromdate) != -1 &&
809
          DateTime->compare($inv->shippingdate,$todate)   == -1;
810
      }
811
      my $openitems = SL::DB::Manager::OrderItem->get_all(where => [ parts_id => $self->part->id, 'order.closed' => 0 ],
812
                                                           with_objects => ['order'],);
813
      my ($not_delivered, $ordered) = 0;
814
      for my $openitem (@{ $openitems }) {
815
        if($openitem -> order -> type eq 'sales_order') {
816
          $not_delivered += $openitem->qty - $openitem->shipped_qty;
817
        } elsif ( $openitem->order->type eq 'purchase_order' ) {
818
          $ordered += $openitem->qty - $openitem->delivered_qty;
819
        }
820
      }
821
      my $print_form = Form->new('');
822
      my $part = $self->part;
823

  
824
      my $stock_amounts = $self->part->get_simple_stock_sql;
825
      $print_form->{type}      = 'part';
826
      $print_form->{printers}  = SL::DB::Manager::Printer->get_all_sorted;
827
      my $output = SL::Presenter->get->render('part/showdetails',
828
          part          => $self->part,
829
          BINS          => \@bindata,
830
          stock_amounts => $stock_amounts,
831
          average       => $average/12,
832
          fromdate      => $fromdate,
833
          todate        => $todate,
834
          sum           => $sum,
835
          reserve_sum   => $reserve_sum,
836
          not_delivered => $not_delivered,
837
          ordered       => $ordered,
838
          type_beleg    => $::form->{type},
839
          type_id       => $::form->{type_id},
840
          maker_id      => $::form->{maker_id},
841
          drawing       => $::form->{drawing},
771
  my @bindata;
772
  my $bins = SL::DB::Manager::Bin->get_all(with_objects => ['warehouse' ]);
773
  my %bins_by_id = map { $_->id => $_ } @$bins;
774
  my $inventories = SL::DB::Manager::Inventory->get_all(where => [ parts_id => $self->part->id],
775
    with_objects => ['parts', 'trans_type' ], sort_by => 'bin_id ASC');
776
  foreach my $bin (@{ $bins }) {
777
    $bin->{qty} = 0;
778
  }
779

  
780
  foreach my $inv (@{ $inventories }) {
781
    my $bin = $bins_by_id{ $inv->bin_id };
782
    $bin->{qty}      += $inv->qty;
783
    $bin->{unit}     =  $inv->parts->unit;
784
  }
785
  my $sum = 0;
786
  for my $bin (@{ $bins }) {
787
    push @bindata , {
788
      'warehouse'    => $bin->warehouse->description,
789
      'description'  => $bin->description,
790
      'qty'          => $bin->{qty},
791
      'unit'         => $bin->{unit},
792
    } if $bin->{qty} != 0;
793

  
794
    $sum += $bin->{qty};
795
  }
796

  
797
  my $todate   = DateTime->now_local;
798
  my $fromdate = DateTime->now_local->add_duration(DateTime::Duration->new(years => -1));
799
  my $average  = 0;
800
  foreach my $inv (@{ $inventories }) {
801
    $average += abs($inv->qty) if $inv->shippingdate && $inv->trans_type->direction eq 'out' &&
802
    DateTime->compare($inv->shippingdate,$fromdate) != -1 &&
803
    DateTime->compare($inv->shippingdate,$todate)   == -1;
804
  }
805
  my $openitems = SL::DB::Manager::OrderItem->get_all(where => [ parts_id => $self->part->id, 'order.closed' => 0 ],
806
    with_objects => ['order'],);
807
  my ($not_delivered, $ordered) = 0;
808
  for my $openitem (@{ $openitems }) {
809
    if($openitem -> order -> type eq 'sales_order') {
810
      $not_delivered += $openitem->qty - $openitem->shipped_qty;
811
    } elsif ( $openitem->order->type eq 'purchase_order' ) {
812
      $ordered += $openitem->qty - $openitem->delivered_qty;
813
    }
814
  }
815

  
816
  my $stock_amounts = $self->part->get_simple_stock_sql;
817

  
818
  my $output = SL::Presenter->get->render('part/showdetails',
819
    part          => $self->part,
820
    stock_amounts => $stock_amounts,
821
    average       => $average/12,
822
    fromdate      => $fromdate,
823
    todate        => $todate,
824
    sum           => $sum,
825
    not_delivered => $not_delivered,
826
    ordered       => $ordered,
842 827
    print_options   => SL::Helper::PrintOptions->get_print_options(
843
      form => $print_form,
844
      options => {dialog_name_prefix => 'print_options.',
845
                  show_headers       => 1,
846
                  no_queue           => 1,
847
                  no_postscript      => 1,
848
                  no_opendocument    => 1,
849
                  hide_language_id_print => 1,
850
                  no_html            => 1},
828
      form => Form->new(
829
        type     => 'part',
830
        printers => SL::DB::Manager::Printer->get_all_sorted,
831
      ),
832
      options => {
833
        dialog_name_prefix     => 'print_options.',
834
        show_headers           => 1,
835
        no_queue               => 1,
836
        no_postscript          => 1,
837
        no_opendocument        => 1,
838
        hide_language_id_print => 1,
839
        no_html                => 1,
840
      },
851 841
    ),
852
      );
853
      $self->render(\$output, { layout => 0, process => 0 });
854
    1;
855
  } or do {
856
  };
842
  );
843
  $self->render(\$output, { layout => 0, process => 0 });
857 844
}
858 845

  
859 846
sub action_print_label {

Auch abrufbar als: Unified diff