summaryrefslogtreecommitdiff
path: root/core/src/Model/TransactionDatabase.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'core/src/Model/TransactionDatabase.cpp')
-rw-r--r--core/src/Model/TransactionDatabase.cpp160
1 files changed, 0 insertions, 160 deletions
diff --git a/core/src/Model/TransactionDatabase.cpp b/core/src/Model/TransactionDatabase.cpp
deleted file mode 100644
index 766727d..0000000
--- a/core/src/Model/TransactionDatabase.cpp
+++ /dev/null
@@ -1,160 +0,0 @@
-#include "TransactionDatabase.hpp"
-
-#include "Model/Project.hpp"
-
-#include <filesystem>
-#include <stdexcept>
-
-namespace fs = std::filesystem;
-
-SalesTable::SalesTable(TransactionDatabase& db)
- // language=SQLite
- : GetRowsStatement(db.GetSQLite(), R"""(
-SELECT * FROM Sales WHERE rowid >= ? AND rowid < ?
-)""")
- // language=SQLite
- // TODO
- , FilterRowsStatement(db.GetSQLite(), R"""(
-)""") {
-}
-
-int SalesTable::GetEntryCont() const {
- // TODO
- return 0;
-}
-
-DeliveryTable::DeliveryTable(TransactionDatabase& db) {
-}
-
-PurchasesTable::PurchasesTable(TransactionDatabase& db) {
-}
-
-static std::string GetDatabaseFilePath(const Project& project) {
- auto dbsDir = project.GetPath() / "databases";
- fs::create_directories(dbsDir);
-
- auto dbFile = dbsDir / "transactions.sqlite3";
- return dbFile.string();
-}
-
-TransactionDatabase::TransactionDatabase(Project& project)
- : mProject{ &project }
- , mDb(GetDatabaseFilePath(project), SQLite::OPEN_READWRITE)
- , mSales(*this)
- , mPurchases(*this)
- , mDeliveries(*this) {
- // Schema
- // - Customer: the customer item ID
- // - Deadline: unix epoch time of order deadline
- // - DeliveryTime: the time this order was completed (through a set of deliveries)
- if (!mDb.tableExists("Sales")) {
- // language=SQLite
- mDb.exec(R"""(
-CREATE TABLE Sales(
- INT PRIMARY KEY,
- Customer INT,
- Deadline DATETIME,
- DeliveryTime DATETIME
-);
-)""");
- }
-
- if (!mDb.tableExists("SalesItems")) {
- // language=SQLite
- mDb.exec(R"""(
-CREATE TABLE SalesItems(
- SaleId INT,
- ItemId INT,
- Count INT
-);
-)""");
- }
-
- // Schema
- // - Factory: the factory id,
- // - OrderTime: the time this order was made
- // - DeliveryTime: the time this order was completed (through a set of deliveries)
- if (!mDb.tableExists("Purchases")) {
- // language=SQLite
- mDb.exec(R"""(
-CREATE TABLE Purchases(
- INT PRIMARY KEY,
- Factory INT,
- OrderTime DATETIME,
- DeliveryTime DATETIME
-);
-)""");
- }
-
- if (!mDb.tableExists("PurchasesItems")) {
- // language=SQLite
- mDb.exec(R"""(
-CREATE TABLE PurchasesItems(
- PurchaseId INT,
- ItemId INT,
- Count INT
-);
-)""");
- }
-
- // Schema
- // - SendTime: unix epoch time of sending to delivery
- // - ArriveTime: unix epoch time of delivery arrived at warehouse; 0 if not arrived yet
- // - AssociatedOrder: rowid of the order that this delivery is completing (which table: Outgoing=true -> Sales, Outgoing=false -> Purchases)
- // - Outgoing: true if the delivery is from warehouse to customer; false if the delivery is from factory to warehouse
- if (!mDb.tableExists("Deliveries")) {
- // language=SQLite
- mDb.exec(R"""(
-CREATE TABLE Deliveries(
- INT PRIMARY KEY,
- SendTime DATETIME,
- ArriveTime DATETIME,
- AssociatedOrder INT,
- Outgoing BOOLEAN
-);
-)""");
- }
-
- if (!mDb.tableExists("DeliveriesItems")) {
- // language=SQLite
- mDb.exec(R"""(
-CREATE TABLE DeliveriesItems(
- DeliveryId INT,
- ItemId INT,
- Count INT
-);
-)""");
- }
-}
-
-const SQLite::Database& TransactionDatabase::GetSQLite() const {
- return mDb;
-}
-
-SQLite::Database& TransactionDatabase::GetSQLite() {
- return mDb;
-}
-
-const SalesTable& TransactionDatabase::GetSales() const {
- return mSales;
-}
-
-SalesTable& TransactionDatabase::GetSales() {
- return mSales;
-}
-
-const PurchasesTable& TransactionDatabase::GetPurchases() const {
- return mPurchases;
-}
-
-PurchasesTable& TransactionDatabase::GetPurchases() {
- return mPurchases;
-}
-
-const DeliveryTable& TransactionDatabase::GetDeliveries() const {
- return mDeliveries;
-}
-
-DeliveryTable& TransactionDatabase::GetDeliveries() {
- return mDeliveries;
-}