Projekt

Allgemein

Profil

« Zurück | Weiter » 

Revision 9f16892d

Von Tamino Steinert vor 6 Tagen hinzugefügt

  • ID 9f16892dfb47a9177cc8f594b206d04384946bc5
  • Vorgänger f7b21f9b
  • Nachfolger 6b17e62c

Varianten: Reiter für Variaten Lagerbestände-/Bewegungen

Unterschiede anzeigen:

SL/DB/Part.pm
489 489
  return $stock_info;
490 490
}
491 491

  
492
sub get_simple_stock_parent_variant_sql {
493
  my ($self, %params) = @_;
494

  
495
  return {} unless $self->id;
496

  
497
  my $query = <<SQL;
498
SELECT
499
  p.partnumber                          AS partnumber,
500
  w.description                         AS warehouse_description,
501
  b.description                         AS bin_description,
502
  SUM(i.qty)                            AS qty,
503
  SUM(i.qty * p.lastcost)               AS stock_value,
504
  p.unit                                AS unit,
505
  LEAD(w.description)           OVER pt AS wh_lead,            -- to detect warehouse changes for subtotals in template
506
  SUM( SUM(i.qty) )             OVER pt AS run_qty,            -- running total of part qty
507
  SUM( SUM(i.qty) )             OVER wh AS wh_run_qty,         -- running total of part warehouse qty
508
  SUM( SUM(i.qty) )             OVER () AS total_qty,          -- running total of all qty
509
  SUM( SUM(i.qty * p.lastcost)) OVER pt AS run_stock_value,    -- running total of part stock_value
510
  SUM( SUM(i.qty * p.lastcost)) OVER wh AS wh_run_stock_value, -- running total of part warehouse stock_value
511
  SUM( SUM(i.qty * p.lastcost)) OVER () AS total_stock_value   -- running total of all stock_value
512
FROM parts_parent_variant_id_parts_variant_id pvv
513
  LEFT JOIN inventory i ON (pvv.variant_id = i.parts_id)
514
  LEFT JOIN parts p     ON (i.parts_id     = p.id)
515
  LEFT JOIN warehouse w ON (i.warehouse_id = w.id)
516
  LEFT JOIN bin b       ON (i.bin_id       = b.id)
517
WHERE parent_variant_id = ?
518
GROUP BY p.partnumber, w.description, w.sortkey, b.description, p.unit, i.parts_id
519
  HAVING SUM(qty) != 0
520
  WINDOW pt AS (PARTITION BY i.parts_id                ORDER BY w.sortkey, b.description, p.unit),
521
         wh AS (PARTITION by i.parts_id, w.description ORDER BY w.sortkey, b.description, p.unit)
522
ORDER BY w.sortkey, b.description, p.unit;
523
SQL
524

  
525
  my $stock_info = selectall_hashref_query($::form, $self->db->dbh, $query, $self->id);
526

  
527
  my %variant_partnumber_to_stock_info;
528
  for (@$stock_info) {
529
    push @{$variant_partnumber_to_stock_info{$_->{partnumber}}}, $_;
530
  }
531
  return \%variant_partnumber_to_stock_info;
532
}
533

  
492 534
sub get_mini_journal {
493 535
  my ($self) = @_;
494 536

  

Auch abrufbar als: Unified diff