Skip to content

Instantly share code, notes, and snippets.

Created March 31, 2019 08:32
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save un1ko85/e0325b98211e9c4cd6a4f14c75a8b9d7 to your computer and use it in GitHub Desktop.
orders.created_at AS created_at, AS product_id,
SELECT string_agg(c.title, ' | ') FROM hm_taxonomies_category_product c_p
JOIN hm_taxonomies_categories c ON c_p.category_id =
WHERE c_p.product_id =
) AS category,
products.title AS product_title,
unit_id.title AS unit_title,
products.on_hand AS stock,
products.sold as sold,
orders_item.quantity AS item_qty, -- количество фасовок в заказе
packings.quantity AS packings_qty, -- количество единиц в фасовках
orders_item.quantity * packings.quantity as product_qty, -- количество единиц
(orders_item.retail_price::float / (10000.0)) / packings.quantity AS retail_price_unit, -- розничная цена единицы
(orders_item.purchase_price::float / (10000.0)) / packings.quantity AS purchase_price_unit, -- закупочная цена единицы
orders_item.retail_price::float / (10000.0) AS retail_price, -- розничная цена фасовки
orders_item.purchase_price::float / (10000.0) AS purchase_price, -- закупочная цена фасовки
-- Надо вывести все в одной колонке
(products.classes->>'revenue_class') || (products.classes->>'profit_class') || '/' || (products.classes->>'variance_class') AS revenue_class
FROM hm_store_orders_items orders_item
JOIN hm_store_orders orders ON = orders_item.order_id
JOIN hm_store_product_packings packings ON = orders_item.purchasable_id
JOIN hm_store_products products ON = packings.product_id
JOIN hm_measure_units unit_id ON = products.unit_id
SELECT state.type
FROM hm_store_states state
WHERE (state.graph = 'order_process' AND state.stateful_type = 'order' AND state.stateful_id =
) <> 'cancelled'
ORDER BY product_id
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment