Compare commits
	
		
			No commits in common. "1a34486a844c1216487e6cca876517e28a460d4b" and "243d91abb31d592b1bf521c68756c6f313f94f41" have entirely different histories.
		
	
	
		
			1a34486a84
			...
			243d91abb3
		
	
		
| @ -22,7 +22,7 @@ flask --app jon run --debug | |||||||
| ## fsmi-db forward | ## fsmi-db forward | ||||||
| 
 | 
 | ||||||
| ``` | ``` | ||||||
| ssh -nNTvL 5432:fsmi-db.fsmi.org:5432 fsmi-login.fsmi.uni-karlsruhe.de | ssh -nNTvL 5432:fsmi-db.fsmi.org:5432 fsmi-login.fsmi.org | ||||||
| ``` | ``` | ||||||
| 
 | 
 | ||||||
| ## TODO | ## TODO | ||||||
|  | |||||||
| @ -1,49 +1,37 @@ | |||||||
| WITH | WITH | ||||||
| most_recent_sales AS ( | most_recent_sales AS ( | ||||||
|   SELECT DISTINCT ON (inventory_line) |     SELECT DISTINCT ON (inventory_line) | ||||||
|     inventory_line, snack_sales_log_id, snack_sales_log_timestamp AS most_recent_sale |         inventory_line, snack_sales_log_id, snack_sales_log_timestamp AS most_recent_sale | ||||||
|   FROM garfield.snack_sales_log |     FROM garfield.snack_sales_log | ||||||
|   ORDER BY inventory_line ASC, snack_sales_log_timestamp DESC |     ORDER BY inventory_line ASC, snack_sales_log_timestamp DESC | ||||||
| ), | ), | ||||||
| enhanced_overview1 AS ( | enhanced_overview AS ( | ||||||
|   SELECT |     SELECT | ||||||
|     inventory_items.item_id, |         inventory_items.item_id, | ||||||
|     inventory_items.item_barcode, |         inventory_items.item_barcode, | ||||||
|     inventory_items.name, |         inventory_items.name, | ||||||
|     units_left, |         units_left, | ||||||
|     inventory_items.sales_units, |         location_name, | ||||||
|     correction_delta, |         location, | ||||||
|     location_name, |         CASE | ||||||
|     location, |             WHEN snack_sales_log_id IS NULL THEN 0 | ||||||
|       CASE |             ELSE sales / (EXTRACT(EPOCH FROM most_recent_sale) - EXTRACT(EPOCH FROM bought)) * 24 * 3600 | ||||||
|         WHEN snack_sales_log_id IS NULL THEN 0 |         END AS per_day | ||||||
|         ELSE sales / (EXTRACT(EPOCH FROM ( |     FROM garfield.inventory_item_overview | ||||||
|           CASE |     LEFT JOIN garfield.inventory_items USING (item_id) | ||||||
|             WHEN units_left <= 0 THEN most_recent_sale |     LEFT JOIN most_recent_sales ON item_id = inventory_line | ||||||
|             ELSE NOW() | ) | ||||||
|           END |      | ||||||
|         )) - EXTRACT(EPOCH FROM bought)) * 24 * 3600 | SELECT | ||||||
|     END AS per_day |  | ||||||
|   FROM garfield.inventory_item_overview |  | ||||||
|   LEFT JOIN garfield.inventory_items USING (item_id) |  | ||||||
|   LEFT JOIN most_recent_sales ON item_id = inventory_line |  | ||||||
| ), |  | ||||||
| enhanced_overview2 AS ( |  | ||||||
|   SELECT |  | ||||||
|     *, |     *, | ||||||
|     CASE |     CASE | ||||||
|       WHEN per_day = 0 THEN NULL |         WHEN per_day = 0 THEN NULL | ||||||
|       ELSE GREATEST(0, units_left / per_day) |         ELSE GREATEST(0, units_left / per_day) | ||||||
|     END AS days_left |     END AS days_left, | ||||||
|   FROM enhanced_overview1 |     CASE | ||||||
| ) |         WHEN per_day = 0 THEN NULL | ||||||
| 
 |         ELSE GREATEST(0, (60 - GREATEST(0, units_left / per_day)) * per_day) | ||||||
| SELECT |     END AS for_two_months | ||||||
|   *, | FROM enhanced_overview | ||||||
|   CASE |  | ||||||
|     WHEN days_left IS NULL THEN NULL |  | ||||||
|     ELSE GREATEST(0, (60 - days_left) * per_day) |  | ||||||
|   END AS for_two_months |  | ||||||
| FROM enhanced_overview2 |  | ||||||
| WHERE (%(location_id)s IS NULL OR location = %(location_id)s) | WHERE (%(location_id)s IS NULL OR location = %(location_id)s) | ||||||
| ORDER BY days_left ASC, per_day DESC | ORDER BY days_left ASC, per_day DESC | ||||||
|  | |||||||
| @ -7,7 +7,6 @@ | |||||||
|     <th>Barcode</th> |     <th>Barcode</th> | ||||||
|     <th>Name</th> |     <th>Name</th> | ||||||
|     <th>Inventar</th> |     <th>Inventar</th> | ||||||
|     <th>Gesamt</th> |  | ||||||
|     <th>Raum</th> |     <th>Raum</th> | ||||||
|     <th>Verbrauch [1/d]</th> |     <th>Verbrauch [1/d]</th> | ||||||
|     <th>ETUE [d]</th> |     <th>ETUE [d]</th> | ||||||
| @ -18,8 +17,7 @@ | |||||||
|     <td><a href="/inventory/item/{{ item.item_id }}">{{ item.item_id }}</a></td> |     <td><a href="/inventory/item/{{ item.item_id }}">{{ item.item_id }}</a></td> | ||||||
|     <td><code>{{ item.item_barcode }}</code></td> |     <td><code>{{ item.item_barcode }}</code></td> | ||||||
|     <td>{{ item.name }}</td> |     <td>{{ item.name }}</td> | ||||||
|     <td class="--align-right">{{ item.units_left + item.correction_delta }}</td> |     <td class="--align-right">{{ item.units_left }}</td> | ||||||
|     <td class="--align-right">{{ item.sales_units }}</td> |  | ||||||
|     <td>{{ item.location_name }}</td> |     <td>{{ item.location_name }}</td> | ||||||
|     <td class="--align-right">{{ item.per_day|round(2) }}</td> |     <td class="--align-right">{{ item.per_day|round(2) }}</td> | ||||||
|     <td class="--align-right">{% if item.days_left != None %}{{ item.days_left|round(1) }}{% endif %}</td> |     <td class="--align-right">{% if item.days_left != None %}{{ item.days_left|round(1) }}{% endif %}</td> | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user