|
|
|
@@ -123,6 +123,41 @@ open class PSService( |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* Bulk import fake on-hand: clear table, then insert rows from Excel. |
|
|
|
* rows: list of maps with keys like "itemCode" and "onHandQty". |
|
|
|
*/ |
|
|
|
fun importFakeOnHand(rows: List<Map<String, Any?>>) { |
|
|
|
// 1. Clear existing overrides |
|
|
|
jdbcDao.executeUpdate("DELETE FROM item_fake_onhand", emptyMap<String, Any>()) |
|
|
|
|
|
|
|
// 2. Normalise and de-duplicate by itemCode (last one wins) |
|
|
|
val byItemCode = LinkedHashMap<String, Number>() |
|
|
|
|
|
|
|
rows.forEach { row -> |
|
|
|
val itemCode = row["itemCode"]?.toString()?.trim() |
|
|
|
if (itemCode.isNullOrBlank()) return@forEach |
|
|
|
|
|
|
|
val rawQty = row["onHandQty"] |
|
|
|
val qty: Number? = when (rawQty) { |
|
|
|
null -> null |
|
|
|
is Number -> rawQty |
|
|
|
else -> rawQty.toString().toDoubleOrNull() |
|
|
|
} |
|
|
|
if (qty == null) return@forEach |
|
|
|
|
|
|
|
byItemCode[itemCode] = qty |
|
|
|
} |
|
|
|
|
|
|
|
// 3. Insert one row per itemCode |
|
|
|
byItemCode.forEach { (itemCode, qty) -> |
|
|
|
jdbcDao.executeUpdate( |
|
|
|
"INSERT INTO item_fake_onhand (itemCode, onHandQty) VALUES (:itemCode, :onHandQty)", |
|
|
|
mapOf("itemCode" to itemCode, "onHandQty" to qty) |
|
|
|
) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
/** Set or clear coffee_or_tea for itemCode + systemType (coffee / tea / lemon). */ |
|
|
|
fun setCoffeeOrTea(itemCode: String, systemType: String, enabled: Boolean) { |
|
|
|
val args = mapOf("itemCode" to itemCode, "systemType" to systemType) |
|
|
|
|