Projekt

Allgemein

Profil

« Zurück | Weiter » 

Revision 3d945302

Von Tamino Steinert vor etwa 1 Jahr hinzugefügt

  • ID 3d945302977cfd54d876c9a3bb526e97533b9c6a
  • Vorgänger 2f9853c8
  • Nachfolger b39696a9

Part: Detailansicht als Popup hinzugefügt

Unterschiede anzeigen:

SL/Controller/Part.pm
24 24
use SL::DB::PriceRuleItem;
25 25
use SL::DB::Shop;
26 26
use SL::Helper::Flash;
27
use SL::Helper::PrintOptions;
27 28
use SL::JSON;
28 29
use SL::Locale::String qw(t8);
29 30
use SL::MoreCommon qw(save_form);
......
739 740
  }
740 741
}
741 742

  
743
sub action_showdetails {
744
  my ($self, %params) = @_;
745

  
746
  eval {
747
      my @bindata;
748
      my $bins = SL::DB::Manager::Bin->get_all(with_objects => ['warehouse' ]);
749
      my %bins_by_id = map { $_->id => $_ } @$bins;
750
      my $inventories = SL::DB::Manager::Inventory->get_all(where => [ parts_id => $self->part->id],
751
                             with_objects => ['parts', 'trans_type' ], sort_by => 'bin_id ASC');
752
      foreach my $bin (@{ $bins }) {
753
          $bin->{qty} = 0;
754
      }
755

  
756
      foreach my $inv (@{ $inventories }) {
757
          my $bin = $bins_by_id{ $inv->bin_id };
758
          $bin->{qty}      += $inv->qty;
759
          $bin->{unit}     =  $inv->parts->unit;
760
          $bin->{reserved} =  defined $inv->reserve_for_id ? 1 : 0;
761
      }
762
      my $sum = 0;
763
      my $reserve_sum = 0;
764
      for my $bin (@{ $bins }) {
765
        push @bindata , {
766
          'warehouse'    => $bin->warehouse->forreserve ? $bin->warehouse->description.' (R)' : $bin->warehouse->description,
767
          'description'  => $bin->description,
768
          'qty'          => $bin->{qty},
769
          'unit'         => $bin->{unit},
770
        } if $bin->{qty} != 0;
771

  
772
        $sum += $bin->{qty};
773
        if($bin->warehouse->forreserve || defined $bin->warehouse->{reserve_for_id}){
774
          $reserve_sum += $bin->{qty};
775
        }
776
      }
777
      # Einfacher ? $sum = $self->part->onhand
778
      my $todate   = DateTime->now_local;
779
      my $fromdate = DateTime->now_local->add_duration(DateTime::Duration->new(years => -1));
780
      my $average  = 0;
781
      foreach my $inv (@{ $inventories }) {
782
        $average += abs($inv->qty) if $inv->shippingdate && $inv->trans_type->direction eq 'out' &&
783
          DateTime->compare($inv->shippingdate,$fromdate) != -1 &&
784
          DateTime->compare($inv->shippingdate,$todate)   == -1;
785
      }
786
      my $openitems = SL::DB::Manager::OrderItem->get_all(where => [ parts_id => $self->part->id, 'order.closed' => 0 ],
787
                                                           with_objects => ['order'],);
788
      my ($not_delivered, $ordered) = 0;
789
      for my $openitem (@{ $openitems }) {
790
        if($openitem -> order -> type eq 'sales_order') {
791
          $not_delivered += $openitem->qty - $openitem->shipped_qty;
792
        } elsif ( $openitem->order->type eq 'purchase_order' ) {
793
          $ordered += $openitem->qty - $openitem->delivered_qty;
794
        }
795
      }
796
      my $print_form = Form->new('');
797
      my $part = $self->part;
798

  
799
      my $stock_amounts = $self->part->get_simple_stock_sql;
800
      $print_form->{type}      = 'part';
801
      $print_form->{printers}  = SL::DB::Manager::Printer->get_all_sorted;
802
      my $output = SL::Presenter->get->render('part/showdetails',
803
          part          => $self->part,
804
          BINS          => \@bindata,
805
          stock_amounts => $stock_amounts,
806
          average       => $average/12,
807
          fromdate      => $fromdate,
808
          todate        => $todate,
809
          sum           => $sum,
810
          reserve_sum   => $reserve_sum,
811
          not_delivered => $not_delivered,
812
          ordered       => $ordered,
813
          type_beleg    => $::form->{type},
814
          type_id       => $::form->{type_id},
815
          maker_id      => $::form->{maker_id},
816
          drawing       => $::form->{drawing},
817
    print_options   => SL::Helper::PrintOptions->get_print_options(
818
      form => $print_form,
819
      options => {dialog_name_prefix => 'print_options.',
820
                  show_headers       => 1,
821
                  no_queue           => 1,
822
                  no_postscript      => 1,
823
                  no_opendocument    => 1,
824
                  hide_language_id_print => 1,
825
                  no_html            => 1},
826
    ),
827
      );
828
      $self->render(\$output, { layout => 0, process => 0 });
829
    1;
830
  } or do {
831
  };
832
}
833

  
834
sub action_print_label {
835
  my ($self) = @_;
836
  # TODO: implement
837
  return $self->render('generic/error', { layout => 1 }, label_error => t8('Not implemented yet!'));
838
}
839

  
742 840
sub action_export_assembly_assortment_components {
743 841
  my ($self) = @_;
744 842

  

Auch abrufbar als: Unified diff