aboutsummaryrefslogtreecommitdiff
path: root/core/src/Model/TransactionsModel.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'core/src/Model/TransactionsModel.cpp')
-rw-r--r--core/src/Model/TransactionsModel.cpp87
1 files changed, 49 insertions, 38 deletions
diff --git a/core/src/Model/TransactionsModel.cpp b/core/src/Model/TransactionsModel.cpp
index 914191d..6d0989e 100644
--- a/core/src/Model/TransactionsModel.cpp
+++ b/core/src/Model/TransactionsModel.cpp
@@ -9,26 +9,28 @@ namespace fs = std::filesystem;
SalesTable::SalesTable(TransactionModel& db)
// language=SQLite
- : GetRowCountStatement(db.GetSQLite(), "SELECT Count(*) FROM Sales")
+ : GetRowCount(db.GetSQLite(), "SELECT Count(*) FROM Sales")
// language=SQLite
- , GetRowsStatement(db.GetSQLite(), "SELECT * FROM Sales WHERE rowid >= ? AND rowid < ?")
- // language=SQLite
- // TODO
- , FilterRowsStatement(db.GetSQLite(), R"""(
-)""") {
+ , GetRows(db.GetSQLite(), "SELECT * FROM Sales WHERE rowid >= ? AND rowid < ?")
+{
}
PurchasesTable::PurchasesTable(TransactionModel& db)
// language=SQLite
- : GetRowCountStatement(db.GetSQLite(), "SELECT Count(*) FROM Purchases")
+ : GetRowCount(db.GetSQLite(), "SELECT Count(*) FROM Purchases")
// language=SQLite
- , GetRowsStatement(db.GetSQLite(), "SELECT * FROM Purchases WHERE rowid >= ? AND rowid < ?") {
+ , GetRows(db.GetSQLite(), "SELECT * FROM Purchases WHERE rowid >= ? AND rowid < ?")
+{
}
-DeliveryTable::DeliveryTable(TransactionModel& db) {
+DeliveryTable::DeliveryTable(TransactionModel& db)
+ // language=SQLite
+ : FilterByTypeAndId(db.GetSQLite(), "SELECT * FROM Deliveries WHERE AssociatedOrder == ? AND Outgoing = ?")
+{
}
-static std::string GetDatabaseFilePath(const Project& project) {
+static std::string GetDatabaseFilePath(const Project& project)
+{
auto dbsDir = project.GetPath() / "databases";
fs::create_directories(dbsDir);
@@ -38,8 +40,8 @@ static std::string GetDatabaseFilePath(const Project& project) {
/// Wrapper for SQLite::Database that creates the default tables
TransactionModel::DatabaseWrapper::DatabaseWrapper(TransactionModel& self)
- : mSqlite(GetDatabaseFilePath(*self.mProject), SQLite::OPEN_READWRITE) {
-
+ : mSqlite(GetDatabaseFilePath(*self.mProject), SQLite::OPEN_READWRITE)
+{
// If this table doesn't exist, the database probably just got initialized
if (mSqlite.tableExists("Sales")) {
return;
@@ -56,8 +58,8 @@ TransactionModel::DatabaseWrapper::DatabaseWrapper(TransactionModel& self)
// - DeliveryTime: the time this order was completed (through a set of deliveries)
// 'Deliveries' schema
- // - SendTime: unix epoch time of sending to delivery
- // - ArriveTime: unix epoch time of delivery arrived at warehouse; 0 if not arrived yet
+ // - ShipmentTime: unix epoch time of sending to delivery
+ // - ArrivalTime: 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
@@ -76,28 +78,28 @@ CREATE TABLE IF NOT EXISTS SalesItems(
);
CREATE TABLE IF NOT EXISTS Purchases(
- INT PRIMARY KEY,
- Factory INT,
- OrderTime DATETIME,
- DeliveryTime DATETIME
+ INT PRIMARY KEY,
+ Factory INT,
+ OrderTime DATETIME,
+ DeliveryTime DATETIME
);
CREATE TABLE IF NOT EXISTS PurchasesItems(
- PurchaseId INT,
- ItemId INT,
- Count INT
+ PurchaseId INT,
+ ItemId INT,
+ Count INT
);
CREATE TABLE IF NOT EXISTS Deliveries(
- INT PRIMARY KEY,
- SendTime DATETIME,
- ArriveTime DATETIME,
- AssociatedOrder INT,
- Outgoing BOOLEAN
+ INT PRIMARY KEY,
+ ShipmentTime DATETIME,
+ ArrivalTime DATETIME,
+ AssociatedOrder INT,
+ Outgoing BOOLEAN
);
CREATE TABLE IF NOT EXISTS DeliveriesItems(
- DeliveryId INT,
- ItemId INT,
- Count INT
+ DeliveryId INT,
+ ItemId INT,
+ Count INT
);
)""");
}
@@ -107,37 +109,46 @@ TransactionModel::TransactionModel(Project& project)
, mDbWrapper(*this)
, mSales(*this)
, mPurchases(*this)
- , mDeliveries(*this) {
+ , mDeliveries(*this)
+{
}
-const SQLite::Database& TransactionModel::GetSQLite() const {
+const SQLite::Database& TransactionModel::GetSQLite() const
+{
return mDbWrapper.mSqlite;
}
-SQLite::Database& TransactionModel::GetSQLite() {
+SQLite::Database& TransactionModel::GetSQLite()
+{
return mDbWrapper.mSqlite;
}
-const SalesTable& TransactionModel::GetSales() const {
+const SalesTable& TransactionModel::GetSales() const
+{
return mSales;
}
-SalesTable& TransactionModel::GetSales() {
+SalesTable& TransactionModel::GetSales()
+{
return mSales;
}
-const PurchasesTable& TransactionModel::GetPurchases() const {
+const PurchasesTable& TransactionModel::GetPurchases() const
+{
return mPurchases;
}
-PurchasesTable& TransactionModel::GetPurchases() {
+PurchasesTable& TransactionModel::GetPurchases()
+{
return mPurchases;
}
-const DeliveryTable& TransactionModel::GetDeliveries() const {
+const DeliveryTable& TransactionModel::GetDeliveries() const
+{
return mDeliveries;
}
-DeliveryTable& TransactionModel::GetDeliveries() {
+DeliveryTable& TransactionModel::GetDeliveries()
+{
return mDeliveries;
}