| 
									
										
										
										
											2020-08-18 19:23:37 +02:00
										 |  |  | CREATE VIEW uihelper_stock_current_overview_including_opened
 | 
					
						
							|  |  |  | AS
 | 
					
						
							|  |  |  | SELECT
 | 
					
						
							|  |  |  |     p.id,
 | 
					
						
							|  |  |  |     sc.amount_opened AS amount_opened,
 | 
					
						
							|  |  |  |     p.tare_weight AS tare_weight,
 | 
					
						
							|  |  |  |     p.enable_tare_weight_handling AS enable_tare_weight_handling,
 | 
					
						
							|  |  |  |     sc.amount AS amount,
 | 
					
						
							| 
									
										
										
										
											2020-10-15 12:46:27 -05:00
										 |  |  |     sc.value as value,
 | 
					
						
							| 
									
										
										
										
											2020-08-18 19:23:37 +02:00
										 |  |  |     sc.product_id AS product_id,
 | 
					
						
							|  |  |  |     sc.best_before_date AS best_before_date,
 | 
					
						
							|  |  |  |     EXISTS(SELECT id FROM stock_missing_products_including_opened WHERE id = sc.product_id) AS product_missing,
 | 
					
						
							|  |  |  |     (SELECT name FROM quantity_units WHERE quantity_units.id = p.qu_id_stock) AS qu_unit_name,
 | 
					
						
							|  |  |  |     (SELECT name_plural FROM quantity_units WHERE quantity_units.id = p.qu_id_stock) AS qu_unit_name_plural,
 | 
					
						
							|  |  |  |     p.name AS product_name,
 | 
					
						
							|  |  |  |     (SELECT name FROM product_groups WHERE product_groups.id = product_group_id) AS product_group_name,
 | 
					
						
							|  |  |  |     EXISTS(SELECT * FROM shopping_list WHERE shopping_list.product_id = sc.product_id) AS on_shopping_list,
 | 
					
						
							|  |  |  |     (SELECT name FROM quantity_units WHERE quantity_units.id = p.qu_id_purchase) AS qu_purchase_unit_name,
 | 
					
						
							|  |  |  |     (SELECT name_plural FROM quantity_units WHERE quantity_units.id = p.qu_id_purchase) AS qu_purchase_unit_name_plural,
 | 
					
						
							|  |  |  |     sc.is_aggregated_amount,
 | 
					
						
							| 
									
										
										
										
											2020-08-25 18:13:26 +02:00
										 |  |  |     sc.amount_opened_aggregated,
 | 
					
						
							| 
									
										
										
										
											2020-11-11 22:06:01 +01:00
										 |  |  |     sc.amount_aggregated,
 | 
					
						
							| 
									
										
										
										
											2020-11-11 22:38:01 +01:00
										 |  |  | 	p.calories AS product_calories,
 | 
					
						
							|  |  |  | 	sc.amount * p.calories AS calories,
 | 
					
						
							| 
									
										
										
										
											2020-11-15 09:57:45 +01:00
										 |  |  | 	sc.amount_aggregated * p.calories AS calories_aggregated,
 | 
					
						
							| 
									
										
										
										
											2020-11-15 19:53:44 +01:00
										 |  |  | 	p.quick_consume_amount,
 | 
					
						
							|  |  |  | 	p.due_type
 | 
					
						
							| 
									
										
										
										
											2020-08-18 19:23:37 +02:00
										 |  |  | FROM (
 | 
					
						
							|  |  |  |         SELECT *
 | 
					
						
							|  |  |  |         FROM stock_current
 | 
					
						
							|  |  |  |         WHERE best_before_date IS NOT NULL
 | 
					
						
							|  |  |  |         UNION
 | 
					
						
							| 
									
										
										
										
											2020-12-22 21:19:55 +01:00
										 |  |  |         SELECT m.id, 0, 0, 0, null, 0, 0, 0
 | 
					
						
							| 
									
										
										
										
											2020-11-15 19:53:44 +01:00
										 |  |  |         FROM stock_missing_products_including_opened m
 | 
					
						
							|  |  |  | 		JOIN products p
 | 
					
						
							|  |  |  | 			ON m.id = p.id
 | 
					
						
							|  |  |  |         WHERE m.id NOT IN (SELECT product_id FROM stock_current)
 | 
					
						
							| 
									
										
										
										
											2020-08-18 19:23:37 +02:00
										 |  |  |     ) sc
 | 
					
						
							|  |  |  | LEFT JOIN products p
 | 
					
						
							| 
									
										
										
										
											2020-12-07 19:48:33 +01:00
										 |  |  |     ON sc.product_id = p.id
 | 
					
						
							| 
									
										
										
										
											2020-12-21 20:43:10 +01:00
										 |  |  | WHERE p.hide_on_stock_overview = 0;
 | 
					
						
							| 
									
										
										
										
											2020-08-18 19:23:37 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | CREATE VIEW uihelper_stock_current_overview
 | 
					
						
							|  |  |  | AS
 | 
					
						
							|  |  |  | SELECT
 | 
					
						
							|  |  |  |     p.id,
 | 
					
						
							|  |  |  |     sc.amount_opened AS amount_opened,
 | 
					
						
							|  |  |  |     p.tare_weight AS tare_weight,
 | 
					
						
							|  |  |  |     p.enable_tare_weight_handling AS enable_tare_weight_handling,
 | 
					
						
							|  |  |  |     sc.amount AS amount,
 | 
					
						
							| 
									
										
										
										
											2020-10-15 12:46:27 -05:00
										 |  |  |     sc.value as value,
 | 
					
						
							| 
									
										
										
										
											2020-08-18 19:23:37 +02:00
										 |  |  |     sc.product_id AS product_id,
 | 
					
						
							|  |  |  |     sc.best_before_date AS best_before_date,
 | 
					
						
							| 
									
										
										
										
											2020-11-11 22:06:01 +01:00
										 |  |  |     EXISTS(SELECT id FROM stock_missing_products WHERE id = sc.product_id) AS product_missing,
 | 
					
						
							| 
									
										
										
										
											2020-08-18 19:23:37 +02:00
										 |  |  |     (SELECT name FROM quantity_units WHERE quantity_units.id = p.qu_id_stock) AS qu_unit_name,
 | 
					
						
							|  |  |  |     (SELECT name_plural FROM quantity_units WHERE quantity_units.id = p.qu_id_stock) AS qu_unit_name_plural,
 | 
					
						
							|  |  |  |     p.name AS product_name,
 | 
					
						
							|  |  |  |     (SELECT name FROM product_groups WHERE product_groups.id = product_group_id) AS product_group_name,
 | 
					
						
							|  |  |  |     EXISTS(SELECT * FROM shopping_list WHERE shopping_list.product_id = sc.product_id) AS on_shopping_list,
 | 
					
						
							|  |  |  |     (SELECT name FROM quantity_units WHERE quantity_units.id = p.qu_id_purchase) AS qu_purchase_unit_name,
 | 
					
						
							|  |  |  |     (SELECT name_plural FROM quantity_units WHERE quantity_units.id = p.qu_id_purchase) AS qu_purchase_unit_name_plural,
 | 
					
						
							|  |  |  |     sc.is_aggregated_amount,
 | 
					
						
							| 
									
										
										
										
											2020-08-25 18:13:26 +02:00
										 |  |  |     sc.amount_opened_aggregated,
 | 
					
						
							| 
									
										
										
										
											2020-11-11 22:06:01 +01:00
										 |  |  |     sc.amount_aggregated,
 | 
					
						
							| 
									
										
										
										
											2020-11-11 22:38:01 +01:00
										 |  |  | 	p.calories AS product_calories,
 | 
					
						
							|  |  |  | 	sc.amount * p.calories AS calories,
 | 
					
						
							| 
									
										
										
										
											2020-11-15 09:57:45 +01:00
										 |  |  | 	sc.amount_aggregated * p.calories AS calories_aggregated,
 | 
					
						
							| 
									
										
										
										
											2020-11-15 19:53:44 +01:00
										 |  |  | 	p.quick_consume_amount,
 | 
					
						
							|  |  |  | 	p.due_type
 | 
					
						
							| 
									
										
										
										
											2020-08-18 19:23:37 +02:00
										 |  |  | FROM (
 | 
					
						
							|  |  |  |         SELECT *
 | 
					
						
							|  |  |  |         FROM stock_current
 | 
					
						
							|  |  |  |         WHERE best_before_date IS NOT NULL
 | 
					
						
							|  |  |  |         UNION
 | 
					
						
							| 
									
										
										
										
											2020-12-23 11:54:39 +01:00
										 |  |  |         SELECT m.id, 0, 0, 0, null, 0, 0, 0
 | 
					
						
							| 
									
										
										
										
											2020-11-15 19:53:44 +01:00
										 |  |  |         FROM stock_missing_products m
 | 
					
						
							|  |  |  | 		JOIN products p
 | 
					
						
							|  |  |  | 			ON m.id = p.id
 | 
					
						
							|  |  |  |         WHERE m.id NOT IN (SELECT product_id FROM stock_current)
 | 
					
						
							| 
									
										
										
										
											2020-08-18 19:23:37 +02:00
										 |  |  |     ) sc
 | 
					
						
							|  |  |  | LEFT JOIN products p
 | 
					
						
							| 
									
										
										
										
											2020-12-07 19:48:33 +01:00
										 |  |  |     ON sc.product_id = p.id
 | 
					
						
							| 
									
										
										
										
											2020-12-21 20:43:10 +01:00
										 |  |  | WHERE p.hide_on_stock_overview = 0;
 |