Project

General

Profile

Revision 5f4bdff3

Added by Sven Schöling over 3 years ago

SL::Helper::ShippedQty: Lagerbewegungen sind negativ im Verkauf

View differences:

SL/Helper/ShippedQty.pm
50 50
      AND to_id = doi.id)
51 51

  
52 52
my $stock_item_links_query = <<'';
53
  SELECT oi.trans_id, oi.id AS oi_id, oi.qty AS oi_qty, oi.unit AS oi_unit, i.qty AS doi_qty, p.unit AS doi_unit
53
  SELECT oi.trans_id, oi.id AS oi_id, oi.qty AS oi_qty, oi.unit AS oi_unit,
54
    (CASE WHEN doe.customer_id > 0 THEN -1 ELSE 1 END) * i.qty AS doi_qty, p.unit AS doi_unit
54 55
  FROM record_links rl
55 56
  INNER JOIN orderitems oi                   ON oi.id = rl.from_id AND rl.from_table = 'orderitems'
56 57
  INNER JOIN delivery_order_items doi        ON doi.id = rl.to_id AND rl.to_table = 'delivery_order_items'
58
  INNER JOIN delivery_orders doe             ON doe.id = doi.delivery_order_id
57 59
  INNER JOIN delivery_order_items_stock dois ON dois.delivery_order_item_id = doi.id
58 60
  INNER JOIN inventory i                     ON dois.id = i.delivery_order_items_stock_id
59 61
  INNER JOIN parts p                         ON p.id = doi.parts_id
......
61 63
  ORDER BY oi.trans_id, oi.position
62 64

  
63 65
my $stock_fill_up_doi_query = <<'';
64
  SELECT doi.id, doi.delivery_order_id, doi.position, doi.parts_id, doi.description, doi.reqdate, doi.serialnumber, i.qty, p.unit
66
  SELECT doi.id, doi.delivery_order_id, doi.position, doi.parts_id, doi.description, doi.reqdate, doi.serialnumber,
67
    (CASE WHEN doe.customer_id > 0 THEN -1 ELSE 1 END) * i.qty, p.unit
65 68
  FROM delivery_order_items doi
66 69
  INNER JOIN parts p                         ON p.id = doi.parts_id
67 70
  INNER JOIN delivery_order_items_stock dois ON dois.delivery_order_item_id = doi.id
71
  INNER JOIN delivery_orders doe             ON doe.id = doi.delivery_order_id
68 72
  INNER JOIN inventory i                     ON dois.id = i.delivery_order_items_stock_id
69 73
  WHERE doi.delivery_order_id IN (
70 74
    SELECT to_id

Also available in: Unified diff