Revision fdfa4918
Von Kivitendo Admin vor mehr als 5 Jahren hinzugefügt
SL/DB/Part.pm | ||
---|---|---|
352 | 352 |
sub bin { require SL::DB::Bin; SL::DB::Manager::Bin ->find_by_or_create(id => $_[0]->{bin_id}) } |
353 | 353 |
} |
354 | 354 |
|
355 |
sub get_simple_stock_sql { |
|
356 |
my ($self, %params) = @_; |
|
357 |
|
|
358 |
return [] unless $self->id; |
|
359 |
|
|
360 |
my $query = <<SQL; |
|
361 |
SELECT w.description AS warehouse_description, |
|
362 |
b.description AS bin_description, |
|
363 |
SUM(i.qty) AS qty, |
|
364 |
SUM(i.qty * p.lastcost) AS stock_value, |
|
365 |
p.unit AS unit, |
|
366 |
LEAD(w.description) OVER pt AS wh_lead, -- to detect warehouse changes for subtotals |
|
367 |
SUM( SUM(i.qty) ) OVER pt AS run_qty, -- running total of total qty |
|
368 |
SUM( SUM(i.qty) ) OVER wh AS wh_run_qty, -- running total of warehouse qty |
|
369 |
SUM( SUM(i.qty * p.lastcost)) OVER pt AS run_stock_value, -- running total of total stock_value |
|
370 |
SUM( SUM(i.qty * p.lastcost)) OVER wh AS wh_run_stock_value -- running total of warehouse stock_value |
|
371 |
FROM inventory i |
|
372 |
LEFT JOIN parts p ON (p.id = i.parts_id) |
|
373 |
LEFT JOIN warehouse w ON (i.warehouse_id = w.id) |
|
374 |
LEFT JOIN bin b ON (i.bin_id = b.id) |
|
375 |
WHERE parts_id = ? |
|
376 |
GROUP BY w.description, b.description, p.unit, i.parts_id |
|
377 |
HAVING SUM(qty) != 0 |
|
378 |
WINDOW pt AS (PARTITION BY i.parts_id ORDER BY w.description, b.description, p.unit), |
|
379 |
wh AS (PARTITION by w.description ORDER BY w.description, b.description, p.unit) |
|
380 |
ORDER BY w.description, b.description |
|
381 |
SQL |
|
382 |
|
|
383 |
my $stock_info = selectall_hashref_query($::form, $self->db->dbh, $query, $self->id); |
|
384 |
return $stock_info; |
|
385 |
} |
|
386 |
|
|
355 | 387 |
sub clone_and_reset_deep { |
356 | 388 |
my ($self) = @_; |
357 | 389 |
|
... | ... | |
567 | 599 |
Please note, that this is a write only accessor, the original Buchungsgruppe can |
568 | 600 |
not be retrieved from an article once set. |
569 | 601 |
|
602 |
=item C<get_simple_stock_sql> |
|
603 |
|
|
604 |
Fetches the qty and the stock value for the current part for each bin and |
|
605 |
warehouse where the part is in stock (or rather different from 0, might be |
|
606 |
negative). |
|
607 |
|
|
608 |
Runs some additional window functions to add the running totals (total running |
|
609 |
total and total per warehouse) for qty and stock value to each line. |
|
610 |
|
|
611 |
Using the LEAD(w.description) the template can check if the warehouse |
|
612 |
description is about to change, i.e. the next line will contain numbers from a |
|
613 |
different warehouse, so that a subtotal line can be added. |
|
614 |
|
|
615 |
The last line will contain the qty total and the total stock value over all |
|
616 |
warehouses/bins and can be used to add a line for the grand totals. |
|
617 |
|
|
570 | 618 |
=item C<items_lastcost_sum> |
571 | 619 |
|
572 | 620 |
Non-recursive lastcost sum of all the items in an assembly or assortment. |
Auch abrufbar als: Unified diff
SL::DB::Part - get_simple_stock_sql: Mengen pro Bin
und Summen über Lager und Gesamtmenge.