Add docker/renumber-rooms.php: room numbers = CASPOS table numbers

Numbers all rooms consecutively from a start number (dry run by
default, --apply to write) and carries the new number into existing
bookings (htl_booking_detail, htl_cart_booking_data) and queued
casposbridge jobs. Used locally: demo rooms GR/DR/ER/LR-101..105 ->
tables 101-120 of the test POS's "Hotel" area.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
DanielS
2026-11-12 00:18:51 +01:00
parent e4db9fae82
commit f4eb1fbc9d
2 changed files with 61 additions and 1 deletions

55
docker/renumber-rooms.php Normal file
View File

@@ -0,0 +1,55 @@
<?php
/**
* Renumber hotel rooms so that room numbers equal CASPOS table numbers.
* docker compose ... exec -u www-data app php docker/renumber-rooms.php 101 (dry run)
* docker compose ... exec -u www-data app php docker/renumber-rooms.php 101 --apply
* Rooms are numbered consecutively from START in the order room type, old number.
* Existing bookings keep their room but get the new number (room_num is copied into
* htl_booking_detail and used by casposbridge as table name).
*/
if (PHP_SAPI !== 'cli') {
exit;
}
define('_PS_ADMIN_DIR_', __DIR__);
require __DIR__.'/../config/config.inc.php';
$start = isset($argv[1]) ? (int)$argv[1] : 0;
$apply = in_array('--apply', $argv, true);
if ($start <= 0) {
fwrite(STDERR, "Usage: php docker/renumber-rooms.php <first table number> [--apply]\n");
exit(1);
}
$db = Db::getInstance();
$rooms = $db->executeS('SELECT ri.`id`, ri.`room_num`, ri.`id_product`, pl.`name`
FROM `'._DB_PREFIX_.'htl_room_information` ri
LEFT JOIN `'._DB_PREFIX_.'product_lang` pl ON pl.`id_product` = ri.`id_product` AND pl.`id_lang` = '.(int)Configuration::get('PS_LANG_DEFAULT').'
ORDER BY ri.`id_hotel`, ri.`id_product`, ri.`room_num`, ri.`id`');
$tables = array();
foreach ($db->executeS('SHOW TABLES') as $t) {
$tables[] = reset($t);
}
$withRoomNum = array();
foreach (array('htl_booking_detail', 'htl_cart_booking_data') as $t) {
if (in_array(_DB_PREFIX_.$t, $tables, true) && $db->executeS('SHOW COLUMNS FROM `'._DB_PREFIX_.$t.'` LIKE \'room_num\'')) {
$withRoomNum[] = $t;
}
}
$n = $start;
foreach ($rooms as $r) {
$new = (string)$n++;
printf("%-28s %-8s -> %s\n", $r['name'], $r['room_num'], $new);
if ($apply && $r['room_num'] !== $new) {
$db->update('htl_room_information', array('room_num' => pSQL($new), 'date_upd' => date('Y-m-d H:i:s')), '`id` = '.(int)$r['id']);
foreach ($withRoomNum as $t) {
$db->update($t, array('room_num' => pSQL($new)), '`id_room` = '.(int)$r['id']);
}
if (in_array(_DB_PREFIX_.'casposbridge_job', $tables, true)) {
// queued (not yet posted) nights follow the new table name
$db->execute('UPDATE `'._DB_PREFIX_.'casposbridge_job` j JOIN `'._DB_PREFIX_.'htl_booking_detail` bd ON bd.`id` = j.`id_htl_booking`
SET j.`table_name` = \''.pSQL($new).'\' WHERE bd.`id_room` = '.(int)$r['id'].' AND j.`status` IN (\'pending\', \'failed\')');
}
}
}
echo $apply ? "Umbenannt.\n" : "Probelauf – mit --apply übernehmen.\n";

View File

@@ -29,7 +29,12 @@ Check-out ──> Gast zahlt an der Kasse wie gewohnt
1. In CASPOS: Zimmer als Tische im eigenen Tischbereich anlegen (Name = Zimmernummer), Artikel für
Übernachtung/Frühstück/Kurtaxe anlegen, einen Kellner „Hotel“ mit Passwort anlegen, OrderApp-API aktivieren.
2. In QloApps: Zimmernummern (Hotel Reservation System → Zimmertypen → Zimmer) auf die Tischnamen setzen.
2. In QloApps: Zimmernummern (Hotel Reservation System → Zimmertypen → Zimmer) auf die Tischnummern setzen –
oder alle Zimmer fortlaufend umnummerieren (erst Probelauf, dann `--apply`; bestehende Buchungen werden mitgezogen):
```bash
docker compose -f docker-compose.yml -f docker-compose.server.yml exec -u www-data app php docker/renumber-rooms.php 101
```
3. *Module → CASPOS Kassenanbindung → Konfigurieren*: IP und API-Port der Kasse (wie in der OrderApp),
bei HTTPS den SHA1-Fingerabdruck, Kellner-Nummer und Passwort.
4. **Verbindung testen** – zeigt Tischbereiche und Artikel mit IDs. Meldet die Kasse „Gerät nicht