69 lines
1.6 KiB
TypeScript
69 lines
1.6 KiB
TypeScript
// point of sales model core
|
|
|
|
import { CSVDatabase } from "./database"
|
|
import { create_csv_database, print_head } from "./database"
|
|
|
|
interface Item {
|
|
id: string
|
|
name: string
|
|
price: number
|
|
// other properties...
|
|
}
|
|
|
|
interface Sale {
|
|
id: string
|
|
itemId: string
|
|
quantity: number
|
|
timestamp: Date
|
|
// other properties...
|
|
}
|
|
|
|
interface Inventory {
|
|
itemId: string
|
|
quantity: number
|
|
}
|
|
|
|
export function create_item_dataframe(items: Item[]): CSVDatabase {
|
|
const filepath = 'data/items.csv'
|
|
return create_csv_database(filepath, items)
|
|
}
|
|
|
|
export function create_sale_dataframe(sales: Sale[]): CSVDatabase {
|
|
const filepath = 'data/sales.csv'
|
|
const data = sales.map(sale => ({
|
|
...sale,
|
|
timestamp: sale.timestamp.toISOString() // Convert Date to string
|
|
}))
|
|
return create_csv_database(filepath, data)
|
|
}
|
|
|
|
export function create_inventory_dataframe(inventories: Inventory[]): CSVDatabase {
|
|
const filepath = 'data/inventory.csv'
|
|
return create_csv_database(filepath, inventories)
|
|
}
|
|
|
|
function create_models() {
|
|
const items: Item[] = [
|
|
{ id: '1', name: 'Item 1', price: 100 },
|
|
{ id: '2', name: 'Item 2', price: 200 }
|
|
]
|
|
|
|
const sales: Sale[] = [
|
|
{ id: '1', itemId: '1', quantity: 2, timestamp: new Date() },
|
|
{ id: '2', itemId: '2', quantity: 1, timestamp: new Date() }
|
|
]
|
|
|
|
const inventories: Inventory[] = [
|
|
{ itemId: '1', quantity: 50 },
|
|
{ itemId: '2', quantity: 30 }
|
|
]
|
|
|
|
const itemDB = create_item_dataframe(items)
|
|
const saleDB = create_sale_dataframe(sales)
|
|
const inventoryDB = create_inventory_dataframe(inventories)
|
|
|
|
print_head(itemDB)
|
|
print_head(saleDB)
|
|
print_head(inventoryDB)
|
|
}
|